Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Timeit module
#6
One of the simplest way beside %%timeit cell magic,is just to put all in string.
import timeit

np_test = '''\
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)
'''

print(timeit.Timer(stmt=np_test).timeit(number=100000))
Output:
3.0972112079055183
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 698 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