summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeth M Morton <seth.m.morton@gmail.com>2016-05-07 23:49:44 -0700
committerSeth M Morton <seth.m.morton@gmail.com>2016-05-08 00:21:12 -0700
commit62098d41f3f137964c5bdd83b8236104114077ad (patch)
treee56c9f9c5b344f351bf5c453fd000b7479d035a1
parent9fa1fdcd771650c5cf7f119447519ede83bcbacb (diff)
downloadnatsort-62098d41f3f137964c5bdd83b8236104114077ad.tar.gz
Profile code now tests what matters.
-rw-r--r--test_natsort/profile_natsorted.py141
1 files changed, 40 insertions, 101 deletions
diff --git a/test_natsort/profile_natsorted.py b/test_natsort/profile_natsorted.py
index 130b652..7efcbf6 100644
--- a/test_natsort/profile_natsorted.py
+++ b/test_natsort/profile_natsorted.py
@@ -9,105 +9,44 @@ import random
import sys
sys.path.insert(0, '.')
-from natsort import natsorted, index_natsorted
+from natsort import natsort_keygen, ns
from natsort.compat.py23 import py23_range
-
-
-# Sample lists to sort
-nums = random.sample(py23_range(10000), 1000)
-nstr = list(map(str, random.sample(py23_range(10000), 1000)))
-astr = ['a'+x+'num' for x in map(str, random.sample(py23_range(10000), 1000))]
-tstr = [['a'+x, 'a-'+x]
- for x in map(str, random.sample(py23_range(10000), 1000))]
-cstr = ['a'+x+'-'+x for x in map(str, random.sample(py23_range(10000), 1000))]
-
-
-def prof_nums(a):
- print('*** Basic Call, Numbers ***')
- for _ in py23_range(1000):
- natsorted(a)
-cProfile.run('prof_nums(nums)', sort='time')
-
-
-def prof_num_str(a):
- print('*** Basic Call, Numbers as Strings ***')
- for _ in py23_range(1000):
- natsorted(a)
-cProfile.run('prof_num_str(nstr)', sort='time')
-
-
-def prof_str(a):
- print('*** Basic Call, Strings ***')
- for _ in py23_range(1000):
- natsorted(a)
-cProfile.run('prof_str(astr)', sort='time')
-
-
-def prof_str_index(a):
- print('*** Basic Index Call ***')
- for _ in py23_range(1000):
- index_natsorted(a)
-cProfile.run('prof_str_index(astr)', sort='time')
-
-
-def prof_nested(a):
- print('*** Basic Call, Nested Strings ***')
- for _ in py23_range(1000):
- natsorted(a)
-cProfile.run('prof_nested(tstr)', sort='time')
-
-
-def prof_str_noexp(a):
- print('*** No-Exp Call ***')
- for _ in py23_range(1000):
- natsorted(a, exp=False)
-cProfile.run('prof_str_noexp(astr)', sort='time')
-
-
-def prof_str_unsigned(a):
- print('*** Unsigned Call ***')
- for _ in py23_range(1000):
- natsorted(a, signed=False)
-cProfile.run('prof_str_unsigned(astr)', sort='time')
-
-
-def prof_str_unsigned_noexp(a):
- print('*** Unsigned No-Exp Call ***')
- for _ in py23_range(1000):
- natsorted(a, signed=False, exp=False)
-cProfile.run('prof_str_unsigned_noexp(astr)', sort='time')
-
-
-def prof_str_asint(a):
- print('*** Int Call ***')
- for _ in py23_range(1000):
- natsorted(a, number_type=int)
-cProfile.run('prof_str_asint(astr)', sort='time')
-
-
-def prof_str_asint_unsigned(a):
- print('*** Unsigned Int (Versions) Call ***')
- for _ in py23_range(1000):
- natsorted(a, number_type=int, signed=False)
-cProfile.run('prof_str_asint_unsigned(astr)', sort='time')
-
-
-def prof_str_key(a):
- print('*** Basic Call With Key ***')
- for _ in py23_range(1000):
- natsorted(a, key=lambda x: x.upper())
-cProfile.run('prof_str_key(astr)', sort='time')
-
-
-def prof_str_index_key(a):
- print('*** Basic Index Call With Key ***')
- for _ in py23_range(1000):
- index_natsorted(a, key=lambda x: x.upper())
-cProfile.run('prof_str_index_key(astr)', sort='time')
-
-
-def prof_str_unorderable(a):
- print('*** Basic Index Call, "Unorderable" ***')
- for _ in py23_range(1000):
- natsorted(a)
-cProfile.run('prof_str_unorderable(cstr)', sort='time')
+import locale
+locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
+
+# Samples to parse
+number = 14695498
+int_string = '43493'
+float_string = '-434.93e7'
+plain_string = 'hello world'
+fancy_string = '7abba9342fdab'
+a_path = '/p/Folder (1)/file (1).tar.gz'
+some_bytes = b'these are bytes'
+a_list = ['hello', 'goodbye', '74']
+
+basic_key = natsort_keygen()
+real_key = natsort_keygen(alg=ns.REAL)
+path_key = natsort_keygen(alg=ns.PATH)
+locale_key = natsort_keygen(alg=ns.LOCALE)
+
+
+def prof_time_to_generate():
+ print('*** Generate Plain Key ***')
+ for _ in py23_range(100000):
+ natsort_keygen()
+cProfile.run('prof_time_to_generate()', sort='time')
+
+
+def prof_parsing(a, msg, key=basic_key):
+ print(msg)
+ for _ in py23_range(100000):
+ key(a)
+cProfile.run('prof_parsing(int_string, "*** Basic Call, Int as String ***")', sort='time')
+cProfile.run('prof_parsing(float_string, "*** Basic Call, Float as String ***")', sort='time')
+cProfile.run('prof_parsing(float_string, "*** Real Call ***", real_key)', sort='time')
+cProfile.run('prof_parsing(number, "*** Basic Call, Number ***")', sort='time')
+cProfile.run('prof_parsing(fancy_string, "*** Basic Call, Mixed String ***")', sort='time')
+cProfile.run('prof_parsing(some_bytes, "*** Basic Call, Byte String ***")', sort='time')
+cProfile.run('prof_parsing(a_path, "*** Path Call ***", path_key)', sort='time')
+cProfile.run('prof_parsing(a_list, "*** Basic Call, Recursive ***")', sort='time')
+cProfile.run('prof_parsing("434,930,000 dollars", "*** Locale Call ***", locale_key)', sort='time')