$ python split_vs_rawlist.py
$ time python splitlist.py
<class 'list'> 1000000
real 0m0.243s
user 0m0.200s
sys 0m0.043s
$ time python rawlist.py
<class 'list'> 1000000
real 0m2.472s
user 0m2.141s
sys 0m0.299s
$ time python -c 'import splitlist'
<class 'list'> 1000000
real 0m0.122s
user 0m0.091s
sys 0m0.031s
$ time python -c 'import rawlist'
<class 'list'> 1000000
real 0m0.494s
user 0m0.447s
sys 0m0.047s
Last active
October 12, 2021 04:49
-
-
Save metatoaster/146c64ef0c053029a921b0bb934469dc 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 random | |
| choices = [chr(i) for i in range(ord('a'), ord('z'))] | |
| with open('rawlist.py', 'w') as rl, open('splitlist.py', 'w') as sp: | |
| rl.write('items = [\n') | |
| sp.write('items = """\n') | |
| for _ in range(1000000): | |
| item = ''.join(random.sample(choices, 10)) | |
| rl.write(" %r,\n" % item) | |
| sp.write("%s\n" % item) | |
| sp.write('"""[1:-1].splitlines()\n') | |
| sp.write('print(type(items), len(items))\n') | |
| rl.write(']\n') | |
| rl.write('print(type(items), len(items))\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment