59 lines
1.8 KiB
Python
59 lines
1.8 KiB
Python
"""冻结旧语言的标准库工作负载;运算与当前三表夹具一致,不翻译业务源码。"""
|
||
|
||
SHAPES = {"standard", "uuid", "calendar"}
|
||
|
||
|
||
def source(shape):
|
||
if shape == "standard":
|
||
return '''required(value: Int?) (out: Int) {
|
||
check value != null else Invalid
|
||
out = value
|
||
}
|
||
roundtrip(value: Int) (out: Int) {
|
||
decorated = " " + int.toText(value) + "雪 "
|
||
trimmed = text.trim(decorated)
|
||
joined = text.join(text.split(trimmed, ""), "")
|
||
out = required(int.parse(text.replace(joined, "雪", "")))
|
||
}
|
||
measure(n: Int) (out: Int) { out = sum(each(roundtrip, range(0, n))) }
|
||
cmd bench = app.measure
|
||
'''
|
||
if shape == "uuid":
|
||
return '''requiredUuid(value: Uuid?) (out: Uuid) {
|
||
check value != null else Invalid
|
||
out = value
|
||
}
|
||
requiredText(value: Text?) (out: Text) {
|
||
check value != null else Invalid
|
||
out = value
|
||
}
|
||
requiredInt(value: Int?) (out: Int) {
|
||
check value != null else Invalid
|
||
out = value
|
||
}
|
||
roundtrip(value: Int) (out: Int) {
|
||
source = "550e8400-e29b-41d4-a716-" + int.toText(value + 100000000000)
|
||
parsed = requiredUuid(uuid.parse(source))
|
||
last = requiredText(text.at(uuid.toText(parsed), 35))
|
||
out = requiredInt(int.parse(last))
|
||
}
|
||
measure(n: Int) (out: Int) { out = sum(each(roundtrip, range(0, n))) }
|
||
cmd bench = app.measure
|
||
'''
|
||
if shape == "calendar":
|
||
return '''roundtrip(offset: Int, start: DateTime) (out: Int) {
|
||
span = dever.time.duration(offset)
|
||
changed = dever.time.add(start, span)
|
||
text = dever.time.formatDatetime(changed)
|
||
restored = dever.time.parseDatetime(text)
|
||
check dever.time.difference(restored, start) == span else Invalid
|
||
out = 1
|
||
}
|
||
measure(n: Int) (out: Int) {
|
||
start = dever.time.parseDatetime("2024-02-29T12:34:56.12+08:00")
|
||
out = sum(each(roundtrip, range(0, n), start))
|
||
}
|
||
cmd bench = app.measure
|
||
'''
|
||
raise ValueError(f"no frozen-language fixture for {shape}")
|