From e0f29b6354005b014f34c2825b94e37434b9e2b7 Mon Sep 17 00:00:00 2001 From: rasbt Date: Tue, 25 Mar 2014 13:58:37 -0400 Subject: [PATCH] timeit test --- timeit_test.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 timeit_test.py diff --git a/timeit_test.py b/timeit_test.py new file mode 100644 index 0000000..31bb93e --- /dev/null +++ b/timeit_test.py @@ -0,0 +1,24 @@ +# Sebastian Raschka, 03/2014 +# comparing string formating: %s and .format() + +import timeit + +format_res = timeit.timeit("['{}'.format(i) for i in range(10000)]", number=1000) + +binaryop_res = timeit.timeit("['%s' %i for i in range(10000)]", number=1000) + +print('{}: {}\n{}: {}'.format('format()', format_res, '%s', binaryop_res)) + +################################ +# On my machine +################################ +# +# Python 3.4.0 +# MacOS X 10.9.2 +# 2.5 GHz Intel Core i5 +# 4 GB 1600 Mhz DDR3 +# +################################ +# format(): 2.815331667999999 +# %s: 1.630353775999538 +################################