Created
August 19, 2011 11:57
-
-
Save eguven/1156652 to your computer and use it in GitHub Desktop.
Some performance test Python2.6 vs Python3.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# procrastination adventures | |
''' | |
RESULTS: (over 1m iterations) | |
Python 2.5 | Python2.6 | Python3.1 | |
test1: ~17.5s | ~14.6s | ~22.1s | |
test2: ~10.6s | ~10.3s | ~16.2s | |
just_join: ~0.7s | ~0.66s | ~0.63s | |
just_sample: ~10.5s | ~9.75s | ~15.7s | |
just_str: ~3.45s | ~3.1s | ~3.4s | |
''' | |
import random | |
def test1(n): | |
for i in range(0,n): | |
''.join(random.sample([str(i) for i in range(0,10)],8)) | |
def test2(n): | |
for i in range(0,n): | |
''.join(random.sample(['0','1','2','3','4','5','6','7','8','9'],8)) | |
def just_join(n): | |
for i in range(0,n): | |
''.join(['0','1','2','3','4','5','6','7']) | |
def just_sample(n): | |
for i in range(0,n): | |
random.sample(['0','1','2','3','4','5','6','7','8','9'],8) | |
def just_str(n): | |
for i in range(0,n): | |
[str(i) for i in ['0','1','2','3','4','5','6','7','8','9']] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment