Created
October 29, 2015 02:21
-
-
Save quasarj/985fdd0e62f5368c530c to your computer and use it in GitHub Desktop.
dict vs list test, for generating IDs
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
13995651 function calls (13995631 primitive calls) in 31.438 seconds | |
Ordered by: standard name | |
ncalls tottime percall cumtime percall filename:lineno(function) | |
5 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:1000(__init__) | |
2 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:1019(init_module_attrs) | |
2 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:1099(create) | |
2/1 0.000 0.000 0.004 0.004 <frozen importlib._bootstrap>:1122(_exec) | |
3 0.000 0.000 0.002 0.001 <frozen importlib._bootstrap>:1156(_load_backward_compatible) | |
5/1 0.000 0.000 0.004 0.004 <frozen importlib._bootstrap>:1186(_load_unlocked) | |
5 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:1266(find_spec) | |
2 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:129(_new_module) | |
5 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:1336(find_spec) | |
3 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:141(__init__) | |
3 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:144(__enter__) | |
2/1 0.000 0.000 0.004 0.004 <frozen importlib._bootstrap>:1465(exec_module) | |
3 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:147(__exit__) | |
12 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:148(<genexpr>) | |
2 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:1534(get_code) | |
2 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:1591(__init__) | |
2 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:1616(get_filename) | |
2 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:1621(get_data) | |
2 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:1631(path_stats) | |
3 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:1697(__init__) | |
3 0.000 0.000 0.002 0.001 <frozen importlib._bootstrap>:1708(load_module) | |
5 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:172(__init__) | |
3 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:1726(is_package) | |
12 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:1729(<genexpr>) | |
31 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:1870(_path_importer_cache) | |
5 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:1887(_legacy_get_spec) | |
5 0.000 0.000 0.001 0.000 <frozen importlib._bootstrap>:1902(_get_spec) | |
5 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:192(acquire) | |
5 0.000 0.000 0.001 0.000 <frozen importlib._bootstrap>:1934(find_spec) | |
5 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:2011(_get_spec) | |
21 0.000 0.000 0.001 0.000 <frozen importlib._bootstrap>:2016(find_spec) | |
15 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:2120(__enter__) | |
15 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:2124(__exit__) | |
5 0.000 0.000 0.001 0.000 <frozen importlib._bootstrap>:2147(_find_spec) | |
5 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:217(release) | |
5/1 0.000 0.000 0.004 0.004 <frozen importlib._bootstrap>:2207(_find_and_load_unlocked) | |
5/1 0.000 0.000 0.004 0.004 <frozen importlib._bootstrap>:2234(_find_and_load) | |
8 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:2264(_handle_fromlist) | |
5 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:257(__init__) | |
5 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:261(__enter__) | |
5 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:268(__exit__) | |
5 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:274(_get_module_lock) | |
5 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:288(cb) | |
21 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:30(_relax_case) | |
5/1 0.000 0.000 0.004 0.004 <frozen importlib._bootstrap>:313(_call_with_frames_removed) | |
4 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:437(cache_from_source) | |
4 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:45(_r_long) | |
101 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:50(_path_join) | |
106 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:518(_verbose_message) | |
101 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:52(<listcomp>) | |
5 0.000 0.000 0.002 0.000 <frozen importlib._bootstrap>:534(_check_name_wrapper) | |
7 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:56(_path_split) | |
2 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:599(_validate_bytecode_header) | |
2 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:654(_compile_bytecode) | |
28 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:68(_path_stat) | |
2 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:728(__init__) | |
2 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:732(__enter__) | |
2 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:739(__exit__) | |
8 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:742(<genexpr>) | |
5 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:78(_path_is_mode_type) | |
10 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:790(__init__) | |
4 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:824(cached) | |
2 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:842(parent) | |
2 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:850(has_location) | |
5 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:87(_path_isfile) | |
5 0.000 0.000 0.000 0.000 <frozen importlib._bootstrap>:884(spec_from_file_location) | |
1248000 0.756 0.000 3.475 0.000 dict-vs-list-test.py:10(make_id_set) | |
1 0.000 0.000 31.438 31.438 dict-vs-list-test.py:2(<module>) | |
1000 0.484 0.000 26.405 0.026 dict-vs-list-test.py:23(list_method) | |
1248000 12.969 0.000 25.819 0.000 dict-vs-list-test.py:27(make_id_list) | |
1000 0.399 0.000 0.964 0.001 dict-vs-list-test.py:38(dict_method) | |
1248000 0.394 0.000 0.474 0.000 dict-vs-list-test.py:42(make_id_dict) | |
1000 0.428 0.000 3.998 0.004 dict-vs-list-test.py:5(set_method) | |
1 0.001 0.001 0.003 0.003 dict-vs-list-test.py:53(generate_data) | |
1 0.065 0.065 31.434 31.434 dict-vs-list-test.py:65(main) | |
1 0.000 0.000 0.002 0.002 hashlib.py:53(<module>) | |
6 0.000 0.000 0.000 0.000 hashlib.py:98(__get_openssl_constructor) | |
1000 0.001 0.000 0.001 0.000 random.py:220(_randbelow) | |
1000 0.001 0.000 0.002 0.000 random.py:250(choice) | |
1 0.000 0.000 0.004 0.004 random.py:37(<module>) | |
1 0.000 0.000 0.000 0.000 random.py:639(SystemRandom) | |
1 0.000 0.000 0.000 0.000 random.py:68(Random) | |
1 0.000 0.000 0.000 0.000 random.py:84(__init__) | |
1 0.000 0.000 0.000 0.000 random.py:93(seed) | |
2 0.000 0.000 0.000 0.000 {built-in method __build_class__} | |
2 0.000 0.000 0.000 0.000 {built-in method _fix_co_filename} | |
15 0.000 0.000 0.000 0.000 {built-in method acquire_lock} | |
10 0.000 0.000 0.000 0.000 {built-in method allocate_lock} | |
8 0.000 0.000 0.000 0.000 {built-in method any} | |
3/1 0.000 0.000 31.438 31.438 {built-in method exec} | |
1 0.000 0.000 0.000 0.000 {built-in method exp} | |
5 0.000 0.000 0.000 0.000 {built-in method from_bytes} | |
10 0.000 0.000 0.000 0.000 {built-in method get_ident} | |
25 0.000 0.000 0.000 0.000 {built-in method getattr} | |
10 0.000 0.000 0.000 0.000 {built-in method getcwd} | |
6 0.000 0.000 0.000 0.000 {built-in method globals} | |
46 0.000 0.000 0.000 0.000 {built-in method hasattr} | |
5 0.000 0.000 0.000 0.000 {built-in method is_builtin} | |
5 0.000 0.000 0.000 0.000 {built-in method is_frozen} | |
34 0.000 0.000 0.000 0.000 {built-in method isinstance} | |
2001011 0.166 0.000 0.166 0.000 {built-in method len} | |
3 0.002 0.001 0.002 0.001 {built-in method load_dynamic} | |
2 0.000 0.000 0.000 0.000 {built-in method loads} | |
2 0.000 0.000 0.000 0.000 {built-in method log} | |
1 0.000 0.000 0.000 0.000 {built-in method openssl_md5} | |
1 0.000 0.000 0.000 0.000 {built-in method openssl_sha1} | |
1 0.000 0.000 0.000 0.000 {built-in method openssl_sha224} | |
1 0.000 0.000 0.000 0.000 {built-in method openssl_sha256} | |
1 0.000 0.000 0.000 0.000 {built-in method openssl_sha384} | |
1 0.000 0.000 0.000 0.000 {built-in method openssl_sha512} | |
20 0.000 0.000 0.000 0.000 {built-in method release_lock} | |
1 0.000 0.000 0.000 0.000 {built-in method sqrt} | |
28 0.000 0.000 0.000 0.000 {built-in method stat} | |
1 0.000 0.000 0.000 0.000 {built-in method urandom} | |
1 0.000 0.000 0.000 0.000 {function Random.seed at 0x10efe3f28} | |
1000000 0.099 0.000 0.099 0.000 {method 'add' of 'set' objects} | |
5745248 0.459 0.000 0.459 0.000 {method 'append' of 'list' objects} | |
1000 0.000 0.000 0.000 0.000 {method 'bit_length' of 'int' objects} | |
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} | |
2 0.000 0.000 0.000 0.000 {method 'endswith' of 'str' objects} | |
5 0.000 0.000 0.000 0.000 {method 'extend' of 'list' objects} | |
5 0.000 0.000 0.000 0.000 {method 'find_loader' of 'zipimport.zipimporter' objects} | |
97 0.000 0.000 0.000 0.000 {method 'format' of 'str' objects} | |
1977 0.000 0.000 0.000 0.000 {method 'getrandbits' of '_random.Random' objects} | |
1496000 15.213 0.000 15.213 0.000 {method 'index' of 'list' objects} | |
105 0.000 0.000 0.000 0.000 {method 'join' of 'str' objects} | |
2 0.000 0.000 0.000 0.000 {method 'read' of '_io.FileIO' objects} | |
42 0.000 0.000 0.000 0.000 {method 'rpartition' of 'str' objects} | |
206 0.000 0.000 0.000 0.000 {method 'rstrip' of 'str' objects} | |
1 0.000 0.000 0.000 0.000 {method 'union' of 'set' objects} |
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
#!/usr/bin/env python3 | |
import random | |
def set_method(data): | |
lst = [] | |
st = set() | |
output = [] | |
def make_id_set(val): | |
if not val in st: | |
st.add(val) | |
lst.append(val) | |
return len(lst) - 1 | |
return lst.index(val) | |
for d in data: | |
output.append(make_id_set(d)) | |
return output | |
def list_method(data): | |
lst = [] | |
output = [] | |
def make_id_list(val): | |
if not val in lst: | |
lst.append(val) | |
return lst.index(val) | |
for d in data: | |
output.append(make_id_list(d)) | |
return output | |
def dict_method(data): | |
dct = {} | |
output = [] | |
def make_id_dict(val): | |
if not val in dct: | |
dct[val] = len(dct) | |
return dct[val] | |
for d in data: | |
output.append(make_id_dict(d)) | |
return output | |
def generate_data(): | |
prefix = "Data_" | |
data = [] | |
for i in range(1000): | |
# do it twice sometimes | |
if random.choice([True, False, False, False]): | |
data.append(prefix + str(i)) | |
data.append(prefix + str(i)) | |
return data | |
def main(): | |
data = generate_data() | |
for i in range(1000): | |
list_method(data) | |
dict_method(data) | |
set_method(data) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment