Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Timeit module
#5
(Jan-28-2018, 02:25 AM)egslava Wrote:
 %%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) 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 1000 random elements, then make them sets (so the set size can be less than 1000, since duplicated elements are removed), then, it calculates their intersection.
what if i want to do s = 1000 and t = 10,000
Reply


Messages In This Thread
Timeit module - by Miraclefruit - Jan-28-2018, 02:00 AM
RE: Timeit module - by egslava - Jan-28-2018, 02:16 AM
RE: Timeit module - by Miraclefruit - Jan-28-2018, 02:23 AM
RE: Timeit module - by egslava - Jan-28-2018, 02:27 AM
RE: Timeit module - by Miraclefruit - Jan-28-2018, 02:29 AM
RE: Timeit module - by snippsat - Jan-28-2018, 03:28 AM
RE: Timeit module - by Miraclefruit - Jan-28-2018, 03:43 AM
RE: Timeit module - by egslava - Jan-28-2018, 03:48 AM
RE: Timeit module - by snippsat - Jan-28-2018, 04:04 AM
RE: Timeit module - by Miraclefruit - Jan-28-2018, 04:16 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pi modules and %timeit RockBlok 3 643 Dec-09-2023, 04:23 PM
Last Post: RockBlok

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020