121 lines
4.4 KiB
Python
121 lines
4.4 KiB
Python
# Copyright (c) PARRRATE T&V 2021. All rights reserved.
|
|
|
|
import random
|
|
from collections import deque
|
|
|
|
from bu4.common_interface import with_common_interface
|
|
from bu4.evaluation.constructs.proxy import antiproxy, eproxy
|
|
from bu4.evaluation.sync import sync
|
|
from bu4.isynced import isynced as synced
|
|
from bu4.linkable.toolchain.parse import parse
|
|
from bu4.linkable.toolchain.readfile import readfile
|
|
from bu4.linkable.toolchain.stdext import standard_extensions
|
|
from bu4.linkable.toolchain.transply import transply
|
|
from bu4.combinatory.tocombinatory import to_combinatory
|
|
from bu4.tracing.probe import Probe
|
|
from bu4.tracing.trace import trace
|
|
from bu4.transform.transform import transform
|
|
from timesample import TimeSample
|
|
|
|
|
|
def deep_trace(sysx):
|
|
hist = []
|
|
queue = deque([(0, 0, sysx)])
|
|
for trace_index in range(1, 1000 + 1):
|
|
hist.append(trace_index)
|
|
if not queue:
|
|
break
|
|
tab, parent, evaluable = queue.popleft()
|
|
hist.append(parent)
|
|
for _ in range(10000):
|
|
evaluable = evaluable.next()
|
|
_probe_index, probe = trace(evaluable)
|
|
hist.append(_probe_index)
|
|
# prefix = ('.', ' ' * tab, parent, trace_index)
|
|
if isinstance(probe, Probe):
|
|
start, list_ = probe.start_and_list()
|
|
hist.append(start)
|
|
for i in range(len(list_)):
|
|
for _ in range(10000):
|
|
list_[i] = list_[i].next()
|
|
# TimeSample.print(*prefix, _probe_index, 'probe', start, f'[ {" ; ".join(map(str, list_))} ]')
|
|
queue.extend((tab + 1, trace_index, deeper_evaluable) for deeper_evaluable in list_)
|
|
else:
|
|
hist.append(None)
|
|
# TimeSample.print(*prefix, '...')
|
|
return hist
|
|
|
|
|
|
print(transform(to_combinatory(transform(parse(transply(
|
|
'/[b]/[a](x)(y)/[x][y]'
|
|
), standard_extensions).link({b'a', b'b'})))))
|
|
|
|
|
|
with TimeSample('all'):
|
|
with TimeSample('sys0'):
|
|
with TimeSample('compilation'):
|
|
sys0 = synced(readfile('src/sys0'))
|
|
with TimeSample('first, AP'):
|
|
TimeSample.print(
|
|
antiproxy(sys0)(0)(1)(
|
|
lambda a: lambda b: a + b
|
|
)(
|
|
lambda n: lambda x: lambda y: x if n == 0 else y
|
|
)(
|
|
lambda n: lambda x: lambda y: x if n & 1 else y
|
|
)(
|
|
lambda n: n >> 1
|
|
)
|
|
)
|
|
with TimeSample('second, AP'):
|
|
TimeSample.print(
|
|
antiproxy(sys0)(0)(1)(
|
|
lambda a: lambda b: a + b
|
|
)(
|
|
lambda n: lambda x: lambda y: x if n == 0 else y
|
|
)(
|
|
lambda n: lambda x: lambda y: x if n & 1 else y
|
|
)(
|
|
lambda n: n >> 1
|
|
)
|
|
)
|
|
with TimeSample('third, EP'):
|
|
sys0 = with_common_interface(sys0)
|
|
TimeSample.print(sys0)
|
|
with TimeSample('sys2'):
|
|
with TimeSample('compilation'):
|
|
sys2c = synced(readfile('src/sys2'))
|
|
with TimeSample('runtime'):
|
|
sys2 = sys2c
|
|
sys2 = with_common_interface(sys2)
|
|
TimeSample.print(sys2)
|
|
with TimeSample('runtime'):
|
|
sys2 = sys2c
|
|
sys2 = with_common_interface(sys2)
|
|
TimeSample.print(sys2)
|
|
with TimeSample('sys3'):
|
|
sys3 = with_common_interface(synced(readfile('src/sys3')))
|
|
sys3 = sync(sys3.call(eproxy(5)))
|
|
TimeSample.print(sys3)
|
|
with TimeSample('sys1'):
|
|
sys1 = with_common_interface(synced(readfile('src/sys1')))
|
|
random.seed(42)
|
|
sys1 = sync(sys1.call(eproxy(random.randrange(2 ** 10))))
|
|
sys1 = sync(sys1.call(eproxy(random.randrange(2 ** 10))))
|
|
sys1 = sync(sys1.call(eproxy(random.randrange(2 ** 10))))
|
|
TimeSample.print(sys1)
|
|
with TimeSample('sys4'):
|
|
TimeSample.print(with_common_interface(synced(readfile('src/sys4'))))
|
|
with TimeSample('sys5'):
|
|
sys5 = synced(readfile('src/sys5'))
|
|
print(deep_trace(sys5))
|
|
with TimeSample('sys6'):
|
|
with TimeSample('compilation'):
|
|
sys6 = synced(readfile('src/sys6')).call(synced('?'))
|
|
with TimeSample('runtime'):
|
|
for _ in range(100):
|
|
sys6 = sys6.next()
|
|
# print(sys6)
|
|
for _ in range(10000000):
|
|
sys6 = sys6.next()
|