Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import csv
- import timeit
- import os
- a = list()
- d = dict()
- s = set()
- f = open("drug_list_v3.csv", "rb")
- reader = csv.reader(f, delimiter=',')
- for row in reader:
- a.append(",".join(row))
- d.setdefault(",".join(row), 1)
- s.add(",".join(row))
- f.close()
- s1 = """\
- o = open("output.csv", 'w')
- (o.write(e+"\\n") for e in d.iterkeys())
- o.close()
- os.remove("output.csv")
- """
- print "dict: ", timeit.timeit(stmt=s1, setup='from __main__ import d, os',
- number=100000)
- s2 = """\
- o = open("output.csv", "w")
- (o.write(e+"\\n") for e in s)
- o.close()
- os.remove("output.csv")
- """
- print "set: ", timeit.timeit(stmt=s2, setup='from __main__ import s, os',
- number=100000)
- s3 = """\
- o = open("output.csv", "w")
- (o.write(e+"\\n") for e in set(a))
- o.close()
- os.remove("output.csv")
- """
- print "list: ", timeit.timeit(stmt=s3, setup='from __main__ import a, os',
- number=100000)
- # o2 = open("output2.csv", "w")
- # for e in s:
- # o2.write(e+"\n")
- # o2.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement