%%timeit import numpy as np NUM_ELEMS = 10 SCALE = 1000 s1 = set( (np.random.rand(NUM_ELEMS) * SCALE).astype('int') ) s2 = set( (np.random.rand(NUM_ELEMS) * SCALE).astype('int') ) s1.intersection(s2)
Quote:The slowest run took 4.28 times longer than the fastest. This could mean that an intermediate result is being cached.
10000 loops, best of 3: 20.8 µs per loop
This code creates two arrays of 10 random items, each is from range [0..1000), then make them sets (so the set size can be less than 1000, since duplicated elements are removed), then, it calculates their intersection.
It's all under %%timeit cell magic, so
timeit
will give you the "benchmark" result :)