File: benchmark.py

package info (click to toggle)
jsonpickle 3.0.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,184 kB
  • sloc: python: 6,088; javascript: 654; makefile: 90; sh: 17
file content (49 lines) | stat: -rwxr-xr-x 1,182 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2008 John Paulett (john -at- paulett.org)
# All rights reserved.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution.

import argparse
import os
import sys
import timeit

json = """\
import feedparser
import jsonpickle
import feedparser_test as test
doc = feedparser.parse(test.RSS_DOC)

jsonpickle.set_preferred_backend('%s')

pickled = jsonpickle.encode(doc)
unpickled = jsonpickle.decode(pickled)
if doc['feed']['title'] != unpickled['feed']['title']:
    print 'Not a match'
"""


if __name__ == '__main__':
    sys.path.insert(1, os.getcwd())

    parser = argparse.ArgumentParser()
    parser.add_argument(
        '-n',
        '--number',
        type=int,
        default=500,
        help='number of iterations to benchmark',
    )
    parser.add_argument('mod', nargs='?', default='json', help='json module')

    args = parser.parse_args()
    mod = args.mod
    number = args.number

    print('Using %s' % mod)
    json_test = timeit.Timer(stmt=json % mod)
    print("%.9f sec/pass " % (json_test.timeit(number=number) / number))