Python noprofile (#138)
* Fixed noprofile / FakeProfiler - omnitrace.libpyomnitrace.profiler.profiler_pause() - omnitrace.libpyomnitrace.profiler.profiler_resume() * Python tests for noprofile * Remove static imported module
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
23fb3946c7
Коммит
3f3ef7ddf9
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
|
||||
|
||||
project(omnitrace-python)
|
||||
|
||||
set(PYTHON_FILES builtin.py external.py source.py)
|
||||
set(PYTHON_FILES builtin.py external.py source.py noprofile.py)
|
||||
|
||||
if(OMNITRACE_INSTALL_EXAMPLES)
|
||||
find_package(Python3 COMPONENTS Interpreter)
|
||||
|
||||
Исполняемый файл
+50
@@ -0,0 +1,50 @@
|
||||
#!@PYTHON_EXECUTABLE@
|
||||
|
||||
import os
|
||||
import sys
|
||||
import random
|
||||
|
||||
_prefix = ""
|
||||
|
||||
|
||||
@noprofile
|
||||
def fib(n):
|
||||
return n if n < 2 else (fib(n - 1) + fib(n - 2))
|
||||
|
||||
|
||||
@noprofile
|
||||
def inefficient(n):
|
||||
print(f"[{_prefix}] ... running inefficient({n})")
|
||||
a = 0
|
||||
for i in range(n):
|
||||
a += i
|
||||
for j in range(n):
|
||||
a += j
|
||||
_len = a * n * n * n
|
||||
_arr = [random.random() for _ in range(_len)]
|
||||
_sum = sum(_arr)
|
||||
print(f"[{_prefix}] ... sum of {_len} random elements: {_sum}")
|
||||
return _sum
|
||||
|
||||
|
||||
@profile
|
||||
def run(n):
|
||||
_ret = 0
|
||||
_ret += fib(n)
|
||||
_ret += inefficient(n)
|
||||
return _ret
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-n", "--num-iterations", help="Number", type=int, default=3)
|
||||
parser.add_argument("-v", "--value", help="Starting value", type=int, default=20)
|
||||
args = parser.parse_args()
|
||||
|
||||
_prefix = os.path.basename(__file__)
|
||||
print(f"[{_prefix}] Executing {args.num_iterations} iterations...\n")
|
||||
for i in range(args.num_iterations):
|
||||
ans = run(args.value)
|
||||
print(f"[{_prefix}] [{i}] result of run({args.value}) = {ans}\n")
|
||||
Ссылка в новой задаче
Block a user