-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.py
executable file
·96 lines (65 loc) · 3.08 KB
/
benchmark.py
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
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#--------------------------------------------------------------------#
# This file is part of Py-notify. #
# #
# Copyright (C) 2007, 2008 Paul Pogonyshev. #
# #
# This library is free software; you can redistribute it and/or #
# modify it under the terms of the GNU Lesser General Public License #
# as published by the Free Software Foundation; either version 2.1 #
# of the License, or (at your option) any later version. #
# #
# This library is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
# Lesser General Public License for more details. #
# #
# You should have received a copy of the GNU Lesser General Public #
# License along with this library; if not, write to the Free #
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, #
# Boston, MA 02110-1301 USA #
#--------------------------------------------------------------------#
import os
import sys
from benchmark import benchmarking
if not os.path.isfile (os.path.join ('notify', 'all.py')):
sys.exit ("%s: cannot find '%s', strange..."
% (sys.argv[0], os.path.join ('notify', 'all.py')))
_extensions_built = False
def _build_extensions ():
global _extensions_built
if not _extensions_built:
print ('Building extension...')
# FIXME: Is that portable enough?
if os.system ('python setup.py build_ext') != 0:
sys.exit (1)
_extensions_built = True
_BENCHMARK_MODULES = ('emission', 'logical')
def _import_module_benchmarks (module_name):
_build_extensions ()
module = __import__('benchmark.%s' % module_name, globals (), locals (), ('*',))
return benchmarking.load_benchmarks (module)
def _create_benchmark_module_importer (module_name):
return lambda: _import_module_benchmarks (module_name)
def _import_all_benchmarks ():
everything = benchmarking.BenchmarkSuite ()
for module_name in _BENCHMARK_MODULES:
everything.append (_import_module_benchmarks (module_name))
return everything
class AllBenchmarks (object):
def __init__(self):
self.everything = _import_all_benchmarks
for module_name in _BENCHMARK_MODULES:
setattr (self, module_name, _create_benchmark_module_importer (module_name))
class BenchmarkProgram (benchmarking.BenchmarkProgram):
def run (self):
_build_extensions ()
benchmarking.BenchmarkProgram.run (self)
BenchmarkProgram (AllBenchmarks (), 'everything')
# Local variables:
# mode: python
# python-indent: 4
# indent-tabs-mode: nil
# fill-column: 90
# End: