Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/actions/setup-decimo/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ runs:
steps:
- uses: prefix-dev/setup-pixi@v0.9.5
with:
cache: true
activate-environment: true
- name: Download decimo.mojopkg artifact
uses: actions/download-artifact@v4
Expand Down
38 changes: 26 additions & 12 deletions .github/workflows/run_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,41 @@ jobs:
run: pip install pre-commit
- name: Format check
run: pre-commit run --all-files
- name: Generate docs (with retry for Mojo compiler intermittent crashes)
- name: Build package (with retry for Mojo compiler intermittent crashes)
run: |
for attempt in 1 2 3; do
echo "=== doc attempt $attempt ==="
if pixi run doc; then
echo "=== doc succeeded on attempt $attempt ==="
echo "=== build attempt $attempt ==="
if pixi run mojo package src/decimo; then
echo "=== build succeeded on attempt $attempt ==="
break
fi
if [ "$attempt" -eq 3 ]; then
echo "=== doc failed after 3 attempts ==="
echo "=== build failed after 3 attempts ==="
exit 1
fi
echo "=== doc crashed, retrying in 5s... ==="
echo "=== build crashed, retrying in 5s... ==="
sleep 5
done
- name: Build package (with retry for Mojo compiler intermittent crashes)
- name: Stage decimo.mojopkg next to tests
# `pixi run doc` documents `src/cli/calculator`, which imports
# `decimo.*`. Mojo 1.0.0b1 cannot resolve those qualified
# references when re-traversing the source tree via `-I src`,
# so the doc task uses `-I tests` against the prebuilt
# `decimo.mojopkg`. Stage it here before invoking doc.
run: cp decimo.mojopkg tests/
- name: Generate docs (with retry for Mojo compiler intermittent crashes)
run: |
for attempt in 1 2 3; do
echo "=== build attempt $attempt ==="
if pixi run mojo package src/decimo; then
echo "=== build succeeded on attempt $attempt ==="
echo "=== doc attempt $attempt ==="
if pixi run doc; then
echo "=== doc succeeded on attempt $attempt ==="
break
fi
if [ "$attempt" -eq 3 ]; then
echo "=== build failed after 3 attempts ==="
echo "=== doc failed after 3 attempts ==="
exit 1
fi
echo "=== build crashed, retrying in 5s... ==="
echo "=== doc crashed, retrying in 5s... ==="
sleep 5
done
- name: Verify decimo.mojopkg was produced
Expand Down Expand Up @@ -309,6 +316,13 @@ jobs:
echo "=== build crashed, retrying in 5s... ==="
sleep 5
done
- name: Stage decimo.mojopkg next to tests
# `tests/test.sh run_cli` and `run_bigfloat` use `-I tests` to load
# the prebuilt `decimo.mojopkg` (Mojo 1.0.0b1's `mojo run/build`
# cannot resolve `decimo.X.Y.foo` qualified references when
# re-traversing source via `-I src`). `pixi run buildcli` produces
# the package at `temp/decimo.mojopkg`, so stage a copy here.
run: cp temp/decimo.mojopkg tests/
- name: Run tests (with retry for Mojo compiler intermittent crashes)
run: |
for attempt in 1 2 3; do
Expand Down
24 changes: 12 additions & 12 deletions benches/bigdecimal/mojo/bench.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ from std.sys import argv as sys_argv
from std.time import perf_counter_ns


fn _now_stamp() raises -> String:
def _now_stamp() raises -> String:
var dt = Python.import_module("datetime")
var now = dt.datetime.now(dt.timezone.utc)
return String(now.strftime("%Y%m%d_%H%M%S"))


fn _csv_quote(s: String) -> String:
def _csv_quote(s: String) -> String:
var needs = False
for ch in s.codepoint_slices():
if ch == "," or ch == '"' or ch == "\n" or ch == "\r":
Expand All @@ -58,7 +58,7 @@ fn _csv_quote(s: String) -> String:
return out


fn _parse_round_param(b: String) raises -> Tuple[Int, RoundingMode]:
def _parse_round_param(b: String) raises -> Tuple[Int, RoundingMode]:
"""Decode "ndigits|MODE" into (ndigits, RoundingMode)."""
var idx = b.find("|")
if idx < 0:
Expand All @@ -82,7 +82,7 @@ fn _parse_round_param(b: String) raises -> Tuple[Int, RoundingMode]:
raise Error("unknown rounding mode: " + mode_str)


fn _cmp_3way(read a: BigDecimal, read b: BigDecimal) raises -> String:
def _cmp_3way(read a: BigDecimal, read b: BigDecimal) raises -> String:
"""Stable, cross-language 3-way comparison: returns "-1", "0", or "1"."""
if a < b:
return String("-1")
Expand All @@ -91,7 +91,7 @@ fn _cmp_3way(read a: BigDecimal, read b: BigDecimal) raises -> String:
return String("0")


fn _round_to_prec(var v: BigDecimal, precision: Int) raises -> BigDecimal:
def _round_to_prec(var v: BigDecimal, precision: Int) raises -> BigDecimal:
"""Round `v` to `precision` significant digits (HALF_EVEN), in-place."""
round_to_precision(
v,
Expand All @@ -103,7 +103,7 @@ fn _round_to_prec(var v: BigDecimal, precision: Int) raises -> BigDecimal:
return v^


fn _emit(v: BigDecimal) raises -> String:
def _emit(v: BigDecimal) raises -> String:
"""Render a BigDecimal in fixed-point (no scientific notation).

Works around a corner case in `BigDecimal.to_string(force_plain=True)`
Expand All @@ -127,7 +127,7 @@ fn _emit(v: BigDecimal) raises -> String:
return s^


fn _result_for(
def _result_for(
op: String,
read a: BigDecimal,
read b: BigDecimal,
Expand Down Expand Up @@ -171,7 +171,7 @@ fn _result_for(
raise Error("unknown op: " + op)


fn _time_kernel(
def _time_kernel(
op: String,
read a: BigDecimal,
read b: BigDecimal,
Expand Down Expand Up @@ -260,7 +260,7 @@ fn _time_kernel(
# precision don't collapse to <1 timer-tick and report 0 ns/iter.
# Returns (iters, reps): reps shrinks to 1 for very-slow ops to bound wall
# time per case at ~500ms.
fn _tune_iters(initial_ns: UInt, hint_iters: Int) -> Tuple[Int, Int]:
def _tune_iters(initial_ns: UInt, hint_iters: Int) -> Tuple[Int, Int]:
comptime TARGET_NS: UInt = 50_000_000 # 50ms per rep target
comptime MIN_RES_NS: UInt = 100_000 # 100µs floor for resolution
comptime MAX_WALL_NS: UInt = 500_000_000 # 500ms total per case
Expand All @@ -287,7 +287,7 @@ fn _tune_iters(initial_ns: UInt, hint_iters: Int) -> Tuple[Int, Int]:
return Tuple[Int, Int](n, reps)


fn _bench_case(
def _bench_case(
op: String,
bc: BenchCase,
iter_hint: Int,
Expand Down Expand Up @@ -340,7 +340,7 @@ fn _bench_case(
return Tuple[String, Float64](result, Float64(best) / Float64(iters))


fn _pad(s: String, w: Int) -> String:
def _pad(s: String, w: Int) -> String:
if len(s) >= w:
return s
var out = s
Expand All @@ -349,7 +349,7 @@ fn _pad(s: String, w: Int) -> String:
return out
Comment thread
forfudan marked this conversation as resolved.


fn main() raises:
def main() raises:
var argv = sys_argv()
var op = String("add")
var cases_dir = String("../cases")
Expand Down
10 changes: 5 additions & 5 deletions benches/decimal128/mojo/bench.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def _csv_quote(s: String) -> String:


def _bench_one[
Body: fn(a: Decimal128, b: Decimal128) raises capturing[_] -> UInt64,
Body: def(a: Decimal128, b: Decimal128) raises capturing[_] -> UInt64,
](a: Decimal128, b: Decimal128, iters: Int) raises -> Float64:
"""Run `Body(a, b)` once per inner iter; best-of-5; returns ns/op.

Expand Down Expand Up @@ -103,7 +103,7 @@ def _bench_to_str(d: Decimal128, iters: Int) raises -> Float64:
for _ in range(REPS):
var t0 = perf_counter_ns()
for _ in range(iters):
sink += UInt64(len(String(d)))
sink += UInt64(String(d).byte_length())
var dt = Int(perf_counter_ns() - t0)
if dt < best:
best = dt
Expand Down Expand Up @@ -229,10 +229,10 @@ def _run_case(


def _pad(s: String, width: Int) -> String:
if len(s) >= width:
if s.byte_length() >= width:
return s
var out = s
var pad = width - len(s)
var pad = width - s.byte_length()
for _ in range(pad):
out += " "
return out
Expand Down Expand Up @@ -278,7 +278,7 @@ def main() raises:
var pair = _run_case(op, bc, iters)
var result = pair[0]
var per = pair[1]
var result_short = result if len(result) <= 30 else String(
var result_short = result if result.byte_length() <= 30 else String(
result[byte=0:30]
)
print(_pad(bc.name, 40), _pad(result_short, 32), per)
Expand Down
Loading
Loading