Last active
July 29, 2020 21:04
-
-
Save JeffLabonte/f97ca6fe0f433323fb0d0f2c38ea3746 to your computer and use it in GitHub Desktop.
List vs Set Python3.8 on Ubuntu 20.04 (Pop!_OS 20.04)
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
********************************** | |
Starting Set TEST with 10 values | |
Set took: 0.04215108300559223s | |
Starting List TEST with 10 values | |
List took: 0.08148651605006307s | |
********************************** | |
********************************** | |
Starting Set TEST with 20 values | |
Set took: 0.03723059198819101s | |
Starting List TEST with 20 values | |
List took: 0.11879940191283822s | |
********************************** | |
********************************** | |
Starting Set TEST with 30 values | |
Set took: 0.03701224492397159s | |
Starting List TEST with 30 values | |
List took: 0.1356453859480098s | |
********************************** | |
********************************** | |
Starting Set TEST with 40 values | |
Set took: 0.03713014104869217s | |
Starting List TEST with 40 values | |
List took: 0.1853324209805578s | |
********************************** | |
********************************** | |
Starting Set TEST with 50 values | |
Set took: 0.03695958503521979s | |
Starting List TEST with 50 values | |
List took: 0.8634760410059243s | |
********************************** | |
********************************** | |
Starting Set TEST with 100 values | |
Set took: 0.03697299200575799s | |
Starting List TEST with 100 values | |
List took: 0.2997861340409145s | |
********************************** | |
********************************** | |
Starting Set TEST with 200 values | |
Set took: 0.03892802097834647s | |
Starting List TEST with 200 values | |
List took: 1.0768143009627238s | |
********************************** | |
********************************** | |
Starting Set TEST with 300 values | |
Set took: 0.037297777947969735s | |
Starting List TEST with 300 values | |
List took: 1.4665326619287953s | |
********************************** | |
********************************** | |
Starting Set TEST with 400 values | |
Set took: 0.057829145109280944s | |
Starting List TEST with 400 values | |
List took: 3.4782891978975385s | |
********************************** | |
********************************** | |
Starting Set TEST with 500 values | |
Set took: 0.05806373502127826s | |
Starting List TEST with 500 values | |
List took: 1.0942066450370476s | |
********************************** | |
********************************** | |
Starting Set TEST with 1000 values | |
Set took: 0.058301003999076784s | |
Starting List TEST with 1000 values | |
List took: 12.732016560970806s | |
********************************** | |
********************************** | |
Starting Set TEST with 1500 values | |
Set took: 0.05864760302938521s | |
Starting List TEST with 1500 values | |
List took: 24.094302967074327s | |
********************************** | |
********************************** | |
Starting Set TEST with 2000 values | |
Set took: 0.05821405095048249s | |
Starting List TEST with 2000 values | |
List took: 17.015575519995764s | |
********************************** |
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
from timeit import timeit | |
import random | |
with open('result.txt', 'w+') as writer: | |
for i in [10, 20, 30, 40, 50, 100, 200, 300, 400, 500, 1000, 1500, 2000,]: | |
writer.write("\n**********************************\n") | |
writer.write(f"Starting Set TEST with {i} values\n") | |
time_took_sec = timeit(stmt=f'{random.randint(0, i)} in s', | |
setup=f's = set(range(0, {i}))') | |
writer.write(f'Set took: {time_took_sec}s\n') | |
writer.write(f"Starting List TEST with {i} values\n") | |
time_took_sec = timeit(stmt=f'{random.randint(0, i)} in s', | |
setup=f's = list(range(0, {i}))') | |
writer.write(f'List took: {time_took_sec}s\n') | |
writer.write("**********************************\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment