Created
December 8, 2014 14:30
-
-
Save poying/fb589d0daffac773171b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import time | |
| n = range(50000) | |
| def test_tuple(): | |
| data = () | |
| for i in n: | |
| data += (1, 2) + (3, 4) | |
| def test_tuple2(): | |
| data = [] | |
| for i in n: | |
| data += list((1, 2)) + list((3, 4)) | |
| def test_list(): | |
| data = [] | |
| for i in n: | |
| data += [1, 2] + [3, 4] | |
| def run(fn): | |
| start = time.time() | |
| fn() | |
| print(time.time() - start) | |
| def bench(): | |
| run(test_tuple) | |
| run(test_tuple2) | |
| run(test_list) | |
| print('-' * 30) | |
| bench() | |
| bench() | |
| bench() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
python 2
python 3