Skip to content

Instantly share code, notes, and snippets.

@renpytom
Created September 17, 2021 03:28
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 renpytom/c6edae881c843c99bd8bb99617ce6e98 to your computer and use it in GitHub Desktop.
Save renpytom/c6edae881c843c99bd8bb99617ce6e98 to your computer and use it in GitHub Desktop.
import cPickle as pickle
import marshal
import time
data = { }
for i in range(1000000):
fn = intern('fn' + str(i // 1000))
data[(fn, i // 1000, i)] = True
# Pickle.
if True:
times = [ ]
for reps in range(10):
start = time.clock()
pickle.dumps(data, pickle.HIGHEST_PROTOCOL)
times.append(time.clock() - start)
times.sort()
print("cPickle:")
print(" ".join("{:.4f}".format(t) for t in times))
# Marshal.
if True:
times = [ ]
for reps in range(10):
start = time.clock()
marshal.dumps(data, 2)
times.append(time.clock() - start)
times.sort()
print("Marshal:")
print(" ".join("{:.4f}".format(t) for t in times))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment