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
26 changes: 17 additions & 9 deletions benches/biguint/bench_biguint_truncate_divide.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ fn run_benchmark_truncate_divide(
speedup_factors: Mojo List to store speedup factors for averaging.
"""
log_print("\nBenchmark: " + name, log_file)
log_print("Dividend: " + dividend, log_file)
log_print("Divisor: " + divisor, log_file)
log_print("Dividend: " + dividend[:1024] + "...", log_file)
log_print("Divisor: " + divisor[:1024] + "...", log_file)

# Set up Mojo and Python values
var mojo_dividend = BigUInt(dividend)
Expand All @@ -93,13 +93,21 @@ fn run_benchmark_truncate_divide(
"Error: Mojo and Python results do not match!",
log_file,
)
log_print("Mojo result: " + String(mojo_result), log_file)
log_print("Python result: " + String(py_result), log_file)
log_print(
"Mojo result: "
+ String(mojo_result)[:1024]
+ String("..."),
log_file,
)
log_print(
"Python result: " + String(py_result)[:1024] + String("..."),
log_file,
)
return # Skip this benchmark case if results don't match

# Display results for verification
log_print("Mojo result: " + String(mojo_result), log_file)
log_print("Python result: " + String(py_result), log_file)
log_print("Mojo result: " + String(mojo_result)[:1024], log_file)
log_print("Python result: " + String(py_result)[:1024], log_file)

# Benchmark Mojo implementation
var t0 = perf_counter_ns()
Expand Down Expand Up @@ -164,7 +172,7 @@ fn main() raises:
log_print("Could not retrieve system information", log_file)

var iterations = 100
var iterations_large_numbers = 10
var iterations_large_numbers = 2

# Define benchmark cases (all positive numbers for BigUInt)
log_print(
Expand Down Expand Up @@ -406,7 +414,7 @@ fn main() raises:

# Case 24: Division of very large numbers
run_benchmark_truncate_divide(
"Division of very large numbers (2250 digits vs 900 digits)",
"Division of very large numbers (250 words vs 100 words)",
"123456789" * 250,
"987654321" * 100,
iterations,
Expand Down Expand Up @@ -502,7 +510,7 @@ fn main() raises:

# Case 31: Division of large numbers
run_benchmark_truncate_divide(
"Division of large numbers (5000 words vs words digits)",
"Division of large numbers (5000 words vs 500 words)",
"316227766_016824890_583648059_893174009_579947593" * 1000,
"141421356_237309504_880168872_420969807_856967187" * 100,
iterations_large_numbers,
Expand Down
9 changes: 5 additions & 4 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ c = "clear && pixi run clean"
# tests (use the mojo testing tool)
test = "pixi run package && pixi run mojo test tests -D ASSERT=all --filter"
t = "clear && pixi run package && pixi run mojo test tests -D ASSERT=all --filter"
b = "pixi run t big"

# benches
bench_decimal = "clear && pixi run package && cd benches/decimal && pixi run mojo -I ../ bench.mojo && cd ../.. && pixi run clean"
bench_bigint = "clear && pixi run package && cd benches/bigint && pixi run mojo -I ../ bench.mojo && cd ../.. && pixi run clean"
bench_biguint = "clear && pixi run package && cd benches/biguint && pixi run mojo -I ../ bench.mojo && cd ../.. && pixi run clean"
bench_bigdecimal = "clear && pixi run package && cd benches/bigdecimal && pixi run mojo -I ../ bench.mojo && cd ../.. && pixi run clean"
bench_decimal = "clear && pixi run package && cd benches/decimal && pixi run mojo run -I ../ -D ASSERT=all bench.mojo && cd ../.. && pixi run clean"
bench_bigint = "clear && pixi run package && cd benches/bigint && pixi run mojo run -I ../ -D ASSERT=all bench.mojo && cd ../.. && pixi run clean"
bench_biguint = "clear && pixi run package && cd benches/biguint && pixi run mojo run -I ../ -D ASSERT=all bench.mojo && cd ../.. && pixi run clean"
bench_bigdecimal = "clear && pixi run package && cd benches/bigdecimal && pixi run mojo run -I ../ -D ASSERT=all bench.mojo && cd ../.. && pixi run clean"
bench_dec = "pixi run bench_decimal"
bench_bint = "pixi run bench_bigint"
bench_buint = "pixi run bench_biguint"
Expand Down
Loading