Skip to content

Instantly share code, notes, and snippets.

@emhart
Created January 15, 2013 06:28
Show Gist options
  • Save emhart/4536646 to your computer and use it in GitHub Desktop.
Save emhart/4536646 to your computer and use it in GitHub Desktop.
'''
import csv
open("test.csv","w").close()
dat = ['one potato','two potato']
dat2 = ['3 potato','four']
dat3 = ['8 potatos','9 potatoes']
mydat = [dat,dat2,dat3]
with open("test.csv","a") as csvfile:
mywriter = csv.writer(csvfile, delimiter=",")
for x in mydat:
mywriter.writerow(x)
'''
import time
import csv
#def data
dat = []
for x in range(500000):
dat.append(["8times"] * 5)
start = time.time()
open("test.csv","w").close()
with open("test.csv","a") as csvfile:
mywriter = csv.writer(csvfile, delimiter=",")
for x in dat:
mywriter.writerow(x)
print (time.time() - start)
start = time.time()
open("test.csv","w").close()
for x in range(500000):
with open("test.csv","a") as csvfile:
mywriter = csv.writer(csvfile, delimiter=",")
mywriter.writerow(dat[x])
print (time.time() - start)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment