Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import print_function
- import timeit
- # Size of list to make random selection from
- LIST_SIZE = 100
- # Number of timeit runs
- NUM_RUNS = 100000
- # Number of items to choose
- NUM_ITEMS = 10
- sample = '''
- import random
- maps = list(range({}))
- def sample(maps, n):
- for i, m in enumerate(random.sample(maps,n)):
- yield i, m
- '''.format(LIST_SIZE)
- shuffle='''
- import random
- maps = list(range({}))
- def shuffle(maps, n):
- new = list(maps)
- random.shuffle(new)
- for i, m in enumerate(new[:n]):
- yield i, m
- '''.format(LIST_SIZE)
- print('***SAMPLE***')
- print(timeit.timeit('list(sample(maps, {}))'.format(NUM_ITEMS), setup=sample, number=NUM_RUNS))
- print('***SHUFFLE**')
- print(timeit.timeit('list(shuffle(maps, {}))'.format(NUM_ITEMS), setup=shuffle, number=NUM_RUNS))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement