Last active
December 24, 2019 22:51
-
-
Save rvprasad/f9c97b1eff3c9b6df92ba3ac7815bd49 to your computer and use it in GitHub Desktop.
Revisions
-
rvprasad revised this gist
Dec 24, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ def time_function(f, data): start = timer() f(data) times.append(timer() - start) print(f'{f.__name__} Mean Time: {statistics.mean(times)} Median Time:{statistics.median(times)}') def extract_uniq_elems_using_list(nums): uniq_elems = [] -
rvprasad renamed this gist
Dec 24, 2019 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
rvprasad created this gist
Dec 24, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ import random import statistics from timeit import default_timer as timer def time_function(f, data): times = [] for _ in range(0, 20): start = timer() f(data) times.append(timer() - start) print(f'function: {f.__name__} Mean Time: {statistics.mean(times)} Median Time:{statistics.median(times)}') def extract_uniq_elems_using_list(nums): uniq_elems = [] for n in nums: uniq_elems.append(n) uniq_elems = set(uniq_elems) def extract_uniq_elems_using_set(nums): uniq_elems = set() for n in nums: uniq_elems.add(n) not_so_randoms = [random.randint(0, 10000) for i in range(0, 10000)] randoms = [random.randint(0, 10000) for i in range(0, 10000)] for i in range(1, 14): print(f'Nums: {len(randoms)}') time_function(extract_uniq_elems_using_set, not_so_randoms) time_function(extract_uniq_elems_using_list, not_so_randoms) time_function(extract_uniq_elems_using_set, randoms) time_function(extract_uniq_elems_using_list, randoms) not_so_randoms *= 2 randoms.extend(random.randint(0, len(randoms)) for i in range(0, len(randoms)))