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
81 changes: 81 additions & 0 deletions benches/bigdecimal/bench_bigdecimal_divide.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ from collections import List

alias PRECISION = 4096
alias ITERATIONS = 100
alias ITERATIONS_LARGE_NUMBERS = 3


fn open_log_file() raises -> PythonObject:
Expand Down Expand Up @@ -758,6 +759,86 @@ fn main() raises:
speedup_factors,
)

# Case 57: Division 65536 words / 65536 words
run_benchmark_divide(
"Division 65536 words / 65536 words",
"123456789" * 32768 + "." + "123456789" * 32768,
"987654321" * 32768 + "." + "987654321" * 32768,
iterations,
log_file,
speedup_factors,
)

# Case 58: Division 262144 words / 262144 words
run_benchmark_divide(
"Division 262144 words / 262144 words",
"123456789" * 131072 + "." + "123456789" * 131072,
"987654321" * 131072 + "." + "987654321" * 131072,
ITERATIONS_LARGE_NUMBERS,
log_file,
speedup_factors,
)

# Case 59: Division 65536 words / 32768 words
run_benchmark_divide(
"Division 65536 words / 32768 words",
"123456789" * 32768 + "." + "123456789" * 32768,
"987654321" * 16384 + "." + "987654321" * 16384,
ITERATIONS_LARGE_NUMBERS,
log_file,
speedup_factors,
)

# Case 60: Division 65536 words / 16384 words
run_benchmark_divide(
"Division 65536 words / 16384 words",
"123456789" * 16384 + "." + "123456789" * 16384,
"987654321" * 8192 + "." + "987654321" * 8192,
ITERATIONS_LARGE_NUMBERS,
log_file,
speedup_factors,
)

# Case 61: Division 65536 words / 8192 words
run_benchmark_divide(
"Division 65536 words / 8192 words",
"123456789" * 8192 + "." + "123456789" * 8192,
"987654321" * 4096 + "." + "987654321" * 4096,
ITERATIONS_LARGE_NUMBERS,
log_file,
speedup_factors,
)

# Case 62: Division 65536 words / 4096 words
run_benchmark_divide(
"Division 65536 words / 4096 words",
"123456789" * 4096 + "." + "123456789" * 4096,
"987654321" * 2048 + "." + "987654321" * 2048,
ITERATIONS_LARGE_NUMBERS,
log_file,
speedup_factors,
)

# Case 63: Division 65536 words / 2048 words
run_benchmark_divide(
"Division 65536 words / 2048 words",
"123456789" * 2048 + "." + "123456789" * 2048,
"987654321" * 1024 + "." + "987654321" * 1024,
ITERATIONS_LARGE_NUMBERS,
log_file,
speedup_factors,
)

# Case 64: Division 65536 words / 1024 words
run_benchmark_divide(
"Division 65536 words / 1024 words",
"123456789" * 1024 + "." + "123456789" * 1024,
"987654321" * 512 + "." + "987654321" * 512,
ITERATIONS_LARGE_NUMBERS,
log_file,
speedup_factors,
)

# Calculate average speedup factor (ignoring any cases that might have failed)
if len(speedup_factors) > 0:
var sum_speedup: Float64 = 0.0
Expand Down
1 change: 1 addition & 0 deletions docs/todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This is a to-do list for DeciMojo.
- [ ] When Mojo supports global variables, implement a global variable for the `BigDecimal` class to store the precision of the decimal number. This will allow users to set the precision globally, rather than having to set it for each function of the `BigDecimal` class.
- [ ] Implement different methods for adding decimojo types with `Int` types so that an implicit conversion is not required.
- [ ] Use debug mode to check for unnecessary zero words before all arithmetic operations. This will help ensure that there are no zero words, which can simplify the speed of checking for zero because we only need to check the first word.
- [ ] Check the `floor_divide()` function of `BigUInt`. Currently, the speed of division between imilar-sized numbers are okay, but the speed of 2n-by-n, 4n-by-n, and 8n-by-n divisions decreases unproportionally. This is likely due to the segmentation of the dividend in the Burnikel-Ziegler algorithm.

- [x] (#31) The `exp()` function performs slower than Python's counterpart in specific cases. Detailed investigation reveals the bottleneck stems from multiplication operations between decimals with significant fractional components. These operations currently rely on UInt256 arithmetic, which introduces performance overhead. Optimization of the `multiply()` function is required to address these performance bottlenecks, particularly for high-precision decimal multiplication with many digits after the decimal point.
- [x] Implement different methods for augmented arithmetic assignments to improve memeory-efficiency and performance.
Expand Down
Loading