Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- from timeit import timeit
- def test_randint():
- return random.randint(1, 2)
- def test_pure_random():
- return random.random()
- def test_pure_random_binary():
- return 1 if random.random() < 0.5 else 2
- if __name__ == '__main__':
- print(timeit(test_randint), 'test_randint')
- print(timeit(test_pure_random), 'test_pure_random')
- print(timeit(test_pure_random_binary), 'test_pure_random_binary')
- """
- 1.306905230000666 test_randint
- 0.13657626399981382 test_pure_random
- 0.1529860969994843 test_pure_random_binary
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement