Skip to content

Instantly share code, notes, and snippets.

@dtaivpp
Last active January 13, 2020 16:01
Show Gist options
  • Save dtaivpp/b1c4fa471faf2981386b39786c5e63d1 to your computer and use it in GitHub Desktop.
Save dtaivpp/b1c4fa471faf2981386b39786c5e63d1 to your computer and use it in GitHub Desktop.
import random
from time import time
import numpy as np
import pandas as pd
# Initilize Random
random.seed(time())
#### List Tests ####
# How many test passes to run
num_tests = 25
# Create a dict for which to store tests
data = {'length':[], 'listComprehension': [], 'append': [], 'preAllocate': [], 'while': []}
for i in range(0, num_tests):
# Randomize list length
end = random.randint(100_000, 10_000_000)
startTime = time()
listComprehension = [i for i in range(0, end)]
endTime = time()
# Add timed entry
tmpdata['listComprehension'].append(endTime - startTime)
# Get the median for all the rows
df = pd.DataFrame(data)
print(df.describe())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment