Skip to content

Instantly share code, notes, and snippets.

@homelinen
Last active August 29, 2015 14:12
Show Gist options
  • Save homelinen/aa0555f1fafc49928137 to your computer and use it in GitHub Desktop.
Save homelinen/aa0555f1fafc49928137 to your computer and use it in GitHub Desktop.
Testing enum as a replacement for tuple primitives.
#!/usr/bin/env python
from enum import Enum
from time import time
class Fruit(Enum):
bannana = (0, 1)
apple = (1, 1)
pear = (5, 5)
print('Start \t{0}'.format(time()))
for i in range(100000):
Fruit.bannana == Fruit.bannana
Fruit.bannana == Fruit.apple
print('End \t{0}'.format(time()))
print('Start \t{0}'.format(time()))
for i in range(100000):
(0, 1) == (0, 1)
(0, 1) == (1, 0)
print('End \t{0}'.format(time()))
yellow = (0, 1)
yellow2 = (0, 1)
red = (5, 5)
print('Start \t{0}'.format(time()))
for i in range(100000):
yellow == yellow2
yellow == red
print('End \t{0}'.format(time()))
"""
Output Time Difference
------
Enum
Start 1419711569.50204
End 1419711570.1128 0.6107521057
Primitive
Start 1419711570.11283
End 1419711570.12255 0.0097191334
Assigned Primitive
Start 1419711570.12256
End 1419711570.13811 0.0155453682
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment