summaryrefslogtreecommitdiff
path: root/test_natsort/profile_natsorted.py
blob: 7978c23f7ca975957929ffc828d21df730caeb23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
from __future__ import print_function
import cProfile
import random
import sys

from natsort import natsorted, index_natsorted


# Sample lists to sort
nums = random.sample(xrange(10000), 1000)
nstr = list(map(str,random.sample(xrange(10000), 1000)))
astr = ['a'+x+'num' for x in map(str,random.sample(xrange(10000), 1000))]
tstr = [['a'+x, 'a-'+x] for x in map(str,random.sample(xrange(10000), 1000))]
cstr = ['a'+x+'-'+x for x in map(str,random.sample(xrange(10000), 1000))]

'''
def prof_nums(a):
    print('*** Basic Call, Numbers ***')
    for _ in xrange(1000):
        natsorted(a)
cProfile.run('prof_nums(nums)', sort='time')


def prof_num_str(a):
    print('*** Basic Call, Numbers as Strings ***')
    for _ in xrange(1000):
        natsorted(a)
cProfile.run('prof_num_str(nstr)', sort='time')
'''

def prof_str(a):
    print('*** Basic Call, Strings ***')
    for _ in xrange(1000):
        natsorted(a)
cProfile.run('prof_str(astr)', sort='time')

'''
def prof_str_index(a):
    print('*** Basic Index Call ***')
    for _ in xrange(1000):
        index_natsorted(a)
cProfile.run('prof_str_index(astr)', sort='time')


def prof_nested(a):
    print('*** Basic Call, Nested Strings ***')
    for _ in xrange(1000):
        natsorted(a)
cProfile.run('prof_nested(tstr)', sort='time')


def prof_str_noexp(a):
    print('*** No-Exp Call ***')
    for _ in xrange(1000):
        natsorted(a, exp=False)
cProfile.run('prof_str_noexp(astr)', sort='time')


def prof_str_unsigned(a):
    print('*** Unsigned Call ***')
    for _ in xrange(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 xrange(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 xrange(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 xrange(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 xrange(1000):
        natsorted(a, key=lambda x: x.upper())
cProfile.run('prof_str_key(astr)', sort='time')
sys.exit()

def prof_str_index_key(a):
    print('*** Basic Index Call With Key ***')
    for _ in xrange(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 xrange(1000):
        natsorted(a)
cProfile.run('prof_str_unorderable(cstr)', sort='time')