File: profile_empty_sequence.py

package info (click to toggle)
elementpath 5.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,452 kB
  • sloc: python: 36,482; xml: 40; makefile: 13
file content (50 lines) | stat: -rwxr-xr-x 1,950 bytes parent folder | download
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
#!/usr/bin/env python
#
# Copyright (c), 2022, SISSA (International School for Advanced Studies).
# All rights reserved.
# This file is distributed under the terms of the MIT License.
# See the file 'LICENSE' in the root directory of the present
# distribution, or http://opensource.org/licenses/MIT.
#
# @author Davide Brunato <brunato@sissa.it>
#
from timeit import timeit
from elementpath.sequences import xlist  # noqa


def run_timeit(stmt='pass', setup='pass', number=1000):
    seconds = timeit(stmt, setup=setup, number=number)
    print("{}: {}s".format(stmt, seconds))


if __name__ == '__main__':
    print('*' * 68)
    print("*** Memory and timing profile of XPath null values alternatives  ***")
    print('*' * 68)
    print()

    NUMBER = 1000
    SETUP = 'from __main__ import xlist'

    print("*** Profile evaluation ***\n")

    run_timeit('[None for _ in range(10000)]', SETUP, NUMBER)
    run_timeit('[[] for _ in range(10000)]', SETUP, NUMBER)
    run_timeit('[xlist() for _ in range(10000)]', SETUP, NUMBER)
    run_timeit('[[] for _ in range(10000)]', SETUP, NUMBER)
    run_timeit('[() for _ in range(10000)]', SETUP, NUMBER)
    run_timeit('xlist([1])', SETUP, NUMBER)
    run_timeit('[xlist() for _ in range(10000)]', SETUP, NUMBER)
    run_timeit('[xlist() for _ in range(10000)]', SETUP, NUMBER)

    print()

    run_timeit('[x for x in range(10000)]', SETUP, NUMBER)
    run_timeit('tuple([x for x in range(10000)])', SETUP, NUMBER)
    run_timeit('list([x for x in range(10000)])', SETUP, NUMBER)
    run_timeit('xlist([x for x in range(10000)])', SETUP, NUMBER)

    run_timeit('\nv = [x for x in range(10000)]\nfor _ in v: pass', SETUP, NUMBER)
    run_timeit('\nv = tuple([x for x in range(10000)])\nfor _ in v: pass', SETUP, NUMBER)
    run_timeit('\nv = list([x for x in range(10000)])\nfor _ in v: pass', SETUP, NUMBER)
    run_timeit('\nv = xlist([x for x in range(10000)])\nfor _ in v: pass', SETUP, NUMBER)