File: test-perf-jsbeautifier.py

package info (click to toggle)
node-js-beautify 1.7.5%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,400 kB
  • sloc: python: 10,222; sh: 848; makefile: 17
file content (36 lines) | stat: -rwxr-xr-x 1,146 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import copy
import jsbeautifier
options = jsbeautifier.default_options()
options.wrap_line_length = 80
data = ''
data_min = ''

def beautifier_test_underscore():
    jsbeautifier.beautify(data, options)

def beautifier_test_underscore_min():
    jsbeautifier.beautify(data_min, options)

def report_perf(fn):
    import timeit
    iter = 50
    time = timeit.timeit(fn + "()", setup="from __main__ import " + fn + "; gc.enable()", number=iter)
    print(fn + ": " + str(iter/time) + " cycles/sec")

if __name__ == '__main__':
    dirname = os.path.dirname(os.path.abspath(__file__))
    underscore_file = os.path.join(dirname, "../../../", "test/resources/underscore.js")
    underscore_min_file = os.path.join(dirname, "../../../", "test/resources/underscore-min.js")
    data = copy.copy(''.join(open(underscore_file).readlines()))
    data_min = copy.copy(''.join(open(underscore_min_file).readlines()))

    # warm up
    beautifier_test_underscore()
    beautifier_test_underscore_min()

    report_perf("beautifier_test_underscore")
    report_perf("beautifier_test_underscore_min")