fork download
  1. import timeit
  2. setup = """
  3. import random
  4. import collections
  5. class User(object):
  6. def __init__(self, a, b):
  7. self.a = a # Always a bool
  8. self.b = b # Always a bool
  9. user_list = [ User( r % 2 == 0, r % 3 == 0 ) for r in (random.randint(0,100) for x in xrange(100)) ]
  10. """
  11. stmt = """
  12. a_count = collections.Counter()
  13. b_count = collections.Counter()
  14.  
  15. for user in user_list:
  16. a_count.update([user.a])
  17. b_count.update([user.b])
  18. """
  19. print timeit.timeit(setup=setup, stmt=stmt, number=1000)
Success #stdin #stdout 0.93s 11040KB
stdin
Standard input is empty
stdout
0.828616142273