72 lines
1.7 KiB
Python
72 lines
1.7 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
#!/usr/bin/env python
|
||
|
|
|
||
|
|
from dataclasses import dataclass, field
|
||
|
|
import sys, re, os, enum, itertools
|
||
|
|
from functools import partial, partialmethod
|
||
|
|
from time import sleep
|
||
|
|
from subprocess import Popen, PIPE, DEVNULL
|
||
|
|
from operator import itemgetter
|
||
|
|
|
||
|
|
from sympy import li
|
||
|
|
from defl import log, cl, Path, Undefined, Null, Assert, Time, Obj, Dunder, IterableType, isIterableType, Run, checkType
|
||
|
|
from defl import CLIError
|
||
|
|
from defl._typing_ import *
|
||
|
|
import defl
|
||
|
|
|
||
|
|
import defl
|
||
|
|
from defl import log, cl, Assert
|
||
|
|
from defl.testing_ import Tester, Test, TestState, testFail
|
||
|
|
|
||
|
|
import dataclasses, contextlib
|
||
|
|
import itertools
|
||
|
|
import inspect
|
||
|
|
from typing import *
|
||
|
|
from types import *
|
||
|
|
import typing
|
||
|
|
from defl._typeCheck_ import *
|
||
|
|
from defl._dataclass_ import *
|
||
|
|
|
||
|
|
def run(cmd):
|
||
|
|
def wrap():
|
||
|
|
Run(['python', '-c', '\n'.join(cmd)]).log().run(T, T).wait().assSuc()
|
||
|
|
|
||
|
|
return wrap
|
||
|
|
|
||
|
|
compare = {
|
||
|
|
'none': [],
|
||
|
|
'import': [
|
||
|
|
'import sys',
|
||
|
|
],
|
||
|
|
'base': [
|
||
|
|
'import sys',
|
||
|
|
'for i in range(10_000):',
|
||
|
|
' ...',
|
||
|
|
],
|
||
|
|
'inside': [
|
||
|
|
'for i in range(10_000):',
|
||
|
|
' import sys',
|
||
|
|
],
|
||
|
|
'none2': [],
|
||
|
|
# 'sleep': [
|
||
|
|
# 'import time',
|
||
|
|
# 'time.sleep( .1)',
|
||
|
|
# ]
|
||
|
|
}
|
||
|
|
# TODO none != none2 ?
|
||
|
|
iters = 1_000
|
||
|
|
res = {k: defl.RollingAverage() for k in compare}
|
||
|
|
pp = defl.ProgressPrint(iters)
|
||
|
|
for i in range(iters):
|
||
|
|
pp.inc(1)
|
||
|
|
for k, v in compare.items():
|
||
|
|
r = defl.timeThis(run(v))
|
||
|
|
res[k] + r
|
||
|
|
# print(k, r, v, res[k])
|
||
|
|
if i % 10 == 0:
|
||
|
|
info = {k: f'{v.avg*1000**2:,.0f}ns' for k, v in res.items()}
|
||
|
|
log.info(lambda jck: jck.info)
|
||
|
|
|
||
|
|
# diff = (resB-resA) / resB
|
||
|
|
# print(f'A={resA:,.2f} B={resB:,.2f} diff={diff:,.2f}')
|