-
-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is bug #2123. Unrelated: [spec/ysh-builtin-eval] Nicer example
- Loading branch information
Andy C
committed
Nov 16, 2024
1 parent
5a67993
commit f4283e5
Showing
4 changed files
with
106 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env bash | ||
|
||
demo() { | ||
local ysh=_bin/cxx-opt/ysh | ||
ninja $ysh | ||
|
||
#OILS_GC_STATS=1 $ysh test/bug-2123.ysh | ||
|
||
# max RSS | ||
# 246 | ||
/usr/bin/time --format '%e %M' $ysh test/bug-2123.ysh | ||
} | ||
|
||
"$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Run with _bin/cxx-opt/ysh | ||
|
||
proc filter (; predicate) { | ||
for line in (io.stdin) { | ||
if (io->evalExpr(predicate, vars={_val: fromJson8(line)})) { | ||
write -- $line | ||
} | ||
} | ||
} | ||
|
||
# | ||
# Setup | ||
# | ||
|
||
var f = '_tmp/b1' | ||
|
||
for i in (0 ..= 100_000) { | ||
json write ({}, space=0) | ||
} > $f | ||
|
||
# | ||
# Benchmarks | ||
# | ||
|
||
var N = 2 | ||
|
||
proc with-default { | ||
write -- u'get() with default\n' | ||
write -- 'BEFORE ------------------------------------------------------' | ||
|
||
for _ in (0 ..< N) { | ||
time for line in (io.stdin) { | ||
call fromJson8(line) | ||
} < $f | ||
write | ||
} | ||
|
||
echo 'FILTER with default' | ||
time filter [get(_val, 'missing-key', 0) === 0] < $f >/dev/null | ||
|
||
write -- 'AFTER -------------------------------------------------------' | ||
|
||
for _ in (0 ..< N) { | ||
time for line in (io.stdin) { | ||
call fromJson8(line) | ||
} < $f | ||
write | ||
} | ||
} | ||
|
||
proc without-default { | ||
write -- u'get() without default\n' | ||
write -- 'BEFORE ------------------------------------------------------' | ||
|
||
for _ in (0 ..< N) { | ||
time for line in (io.stdin) { | ||
call fromJson8(line) | ||
} < $f | ||
write | ||
} | ||
|
||
echo 'FILTER without default' | ||
time filter [get(_val, 'missing-key')] < $f #>/dev/null | ||
|
||
write -- 'AFTER -------------------------------------------------------' | ||
|
||
for _ in (0 ..< N) { | ||
time for line in (io.stdin) { | ||
call fromJson8(line) | ||
} < $f | ||
write | ||
} | ||
} | ||
|
||
|
||
with-default | ||
without-default | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters