Skip to content

Instantly share code, notes, and snippets.

@Bennyelg
Last active February 12, 2019 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bennyelg/cfaa2176f82a09b37bec3457c3147506 to your computer and use it in GitHub Desktop.
Save Bennyelg/cfaa2176f82a09b37bec3457c3147506 to your computer and use it in GitHub Desktop.
dedup python and nim test
import random
import dedupnim # (dedupnim) https://gist.github.com/Bennyelg/d472cc66d3150d0bb549c14c9a17c253
def remove_duplicates(n):
return list({e for e in n})
def remove_duplicates2(n):
return {e: 1 for e in n}.keys()
if __name__ == '__main__':
# first_method (python sets): 0.493056058883667
# second_method (python dicts): 0.5922470092773438
# tierd_method (nim tables): 0.1646420955657959
# fourth_method (nim intsets): 0.14032793045043945
i = 0
while i != 10:
ls = []
while len(ls) < 10_000_000:
ls.append(random.randint(0, 1_000))
import time
f1_start = time.time()
remove_duplicates(ls)
print(f"First_method: {time.time() - f1_start}\n")
f1_start = time.time()
remove_duplicates2(ls)
print(f"Second_method: {time.time() - f1_start}\n")
f1_start = time.time()
dedupnim.remove_duplications_nim(ls)
print(f"Third_method: {time.time() - f1_start}\n")
f1_start = time.time()
dedupnim.remove_duplications_nim_with_sets(ls)
print(f"Fourth_method: {time.time() - f1_start}\n")
i += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment