X Tutup
Skip to content

Improve hexbin performance#7944

Merged
NelleV merged 2 commits intomatplotlib:masterfrom
dstansby:hexbin-speedup
Jan 25, 2017
Merged

Improve hexbin performance#7944
NelleV merged 2 commits intomatplotlib:masterfrom
dstansby:hexbin-speedup

Conversation

@dstansby
Copy link
Copy Markdown
Member

A large chunk of time in hexbin is spent binning the data. This PR speeds that up by converting some if statements to matrix multiplication, and reducing the length of the remaining for loops.

I've tested the speedup using the following code:

import matplotlib.pyplot as plt
import numpy as np
import time

for i in range(1, 7):
    x = np.random.rand(10**i)
    y = np.random.rand(10**i)
    start = time.time()
    plt.hexbin(x, y)
    end = time.time()
    print(i, end - start)

Before, this prints

1 0.07006597518920898
2 0.0029900074005126953
3 0.0072820186614990234
4 0.0190579891204834
5 0.19024014472961426
6 1.8048720359802246

After my changes it prints

1 0.06623506546020508
2 0.002410888671875
3 0.006618022918701172
4 0.009796142578125
5 0.1008000373840332
6 0.9016518592834473

so for large arrays there's ~50% speedup.

@tacaswell tacaswell added this to the 2.1 (next point release) milestone Jan 25, 2017
@NelleV
Copy link
Copy Markdown
Member

NelleV commented Jan 25, 2017

Thanks @dstansby !

@NelleV NelleV merged commit 041a9ca into matplotlib:master Jan 25, 2017
@dstansby
Copy link
Copy Markdown
Member Author

No problem! (as you can probably guess I've been using hexbin quite a bit lately!)

@dstansby dstansby deleted the hexbin-speedup branch February 14, 2017 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

X Tutup