|
| 1 | +import clr |
| 2 | + |
| 3 | +from pyrevit import PYTHON_LIB_DIR, MAIN_LIB_DIR |
| 4 | +from pyrevit.coreutils import Timer |
| 5 | + |
| 6 | +from scriptutils import this_script |
| 7 | + |
| 8 | +clr.AddReference('System') |
| 9 | +clr.AddReference('IronPython') |
| 10 | +# noinspection PyUnresolvedReferences |
| 11 | +from System.Collections.Generic import List |
| 12 | +# noinspection PyUnresolvedReferences |
| 13 | +import IronPython.Hosting |
| 14 | +import IronPython.Runtime |
| 15 | + |
| 16 | + |
| 17 | +TEST_UNIT = 100 |
| 18 | +MAX_TESTS = 5 * TEST_UNIT |
| 19 | +script = "import random; random.randint(1,10)" |
| 20 | + |
| 21 | + |
| 22 | +def run(engine, runtime): |
| 23 | + scope = runtime.CreateScope() |
| 24 | + co = engine.GetCompilerOptions(scope) |
| 25 | + # co.Module &= ~IronPython.Runtime.ModuleOptions.Optimized |
| 26 | + source = engine.CreateScriptSourceFromString(script) |
| 27 | + comped = source.Compile() |
| 28 | + comped.Execute(scope) |
| 29 | + |
| 30 | + |
| 31 | +def make_engine(): |
| 32 | + options = {"Frames": True, "FullFrames": True, "LightweightScopes": True} |
| 33 | + engine = IronPython.Hosting.Python.CreateEngine(options) |
| 34 | + engine.SetSearchPaths(List[str]([PYTHON_LIB_DIR, MAIN_LIB_DIR])) |
| 35 | + runtime = engine.Runtime |
| 36 | + return engine, runtime |
| 37 | + |
| 38 | + |
| 39 | +def shutdown(runtime): |
| 40 | + runtime.Shutdown() |
| 41 | + |
| 42 | + |
| 43 | +engine_times = [] |
| 44 | +output_times = [] |
| 45 | + |
| 46 | +for idx in range(1, MAX_TESTS): |
| 47 | + engine, runtime = make_engine() |
| 48 | + engine_timer = Timer() |
| 49 | + run(engine, runtime) |
| 50 | + eng_time = engine_timer.get_time() |
| 51 | + shutdown(runtime) |
| 52 | + engine_times.append(eng_time) |
| 53 | + |
| 54 | + output_timer = Timer() |
| 55 | + print('Engine {}: {}'.format(idx, eng_time)) |
| 56 | + output_times.append(output_timer.get_time()) |
| 57 | + |
| 58 | + |
| 59 | +chart = this_script.output.make_line_chart() |
| 60 | +# chart.options.scales = {'xAxes': [{'ticks': {'fixedStepSize': 5}, 'type': 'category', 'position': 'bottom'}], |
| 61 | +# 'yAxes': [{'ticks': {'fixedStepSize': 10}}]} |
| 62 | + |
| 63 | +chart.data.labels = [x for x in range(0, MAX_TESTS + 1)] |
| 64 | + |
| 65 | +engine_dataset = chart.data.new_dataset('engine_timer') |
| 66 | +engine_dataset.set_color(0xc3, 0x10, 0x10, 0.4) |
| 67 | +engine_dataset.data = engine_times |
| 68 | + |
| 69 | +output_dataset = chart.data.new_dataset('output_timer') |
| 70 | +output_dataset.set_color(0xf0, 0xa7, 0x19, 0.4) |
| 71 | +output_dataset.data = output_times |
| 72 | + |
| 73 | +chart.draw() |
0 commit comments