Skip to content

Commit 9ca39d4

Browse files
committed
added Rust improvement and numba results to README closes #8
1 parent bc2111d commit 9ca39d4

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

README.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,13 +486,58 @@ test_itertools 56,762.8920 (119.05) 69,660.0200 (83.87) 58,4
486486
487487
> NOTE: If you want to propose changes or improvements send a PR here: https://github.com/rochacbruno/rust-python-example/
488488
489+
490+
I received more contributions as Pull Requests one of then was by [Jason Knight](https://github.com/binarybana) to improve `Rust` using
491+
492+
```bash
493+
RUSTFLAGS="-C target-cpu=native" cargo build --release
494+
```
495+
496+
And for those who were curious about a comparison with `numba` so [Shyba](https://github.com/shyba) implemented it and it is available in the numba branch https://github.com/rochacbruno/rust-python-example/tree/numba.
497+
498+
```python
499+
from numba import jit
500+
501+
@jit(nopython=True, cache=True)
502+
def count_doubles_once_numba(val):
503+
total = 0
504+
chars = iter(val)
505+
c1 = next(chars)
506+
for c2 in chars:
507+
if c1 == c2:
508+
total += 1
509+
c1 = c2
510+
return total
511+
```
512+
513+
Look the new results with **numba** at the top, pretty close to **Rust**
514+
515+
```bash
516+
----------------------------------------------------------------------------------------------------
517+
Name (time in us) Min Max Mean
518+
----------------------------------------------------------------------------------------------------
519+
test_pure_python_once_numba 292.0990 (1.0) 317.7590 (1.0) 296.7477 (1.0)
520+
test_numpy_numba 326.2470 (1.12) 526.1350 (1.66) 338.1704 (1.14)
521+
test_rust_bytes_once 336.0620 (1.15) 1,053.0090 (3.31) 342.5122 (1.15)
522+
test_c_swig_bytes_once 375.6310 (1.29) 1,389.9070 (4.37) 388.9181 (1.31)
523+
test_rust_once 986.0360 (3.38) 2,498.5850 (7.86) 1,006.5819 (3.39)
524+
test_numpy 1,137.1750 (3.89) 2,000.5430 (6.30) 1,167.2551 (3.93)
525+
test_rust 2,555.1400 (8.75) 3,645.3900 (11.47) 2,592.0419 (8.73)
526+
test_regex 22,597.1750 (77.36) 25,027.2820 (78.76) 22,851.8456 (77.01)
527+
test_pure_python_once 32,418.8830 (110.99) 34,818.0800 (109.57) 32,756.3244 (110.38)
528+
test_pure_python 43,823.5140 (150.03) 45,961.8460 (144.64) 44,367.1028 (149.51)
529+
test_python_comprehension 46,360.1640 (158.71) 50,578.1740 (159.17) 46,986.8058 (158.34)
530+
test_itertools 49,080.8640 (168.03) 51,016.5230 (160.55) 49,405.2562 (166.49)
531+
----------------------------------------------------------------------------------------------------
532+
```
533+
489534
# Conclusion
490535
491536
Back to the purpose of this post "How to Speed Up your Python with Rust" we started with:
492537
493538
- **Pure Python** function taking **102 ms**.
494539
- Improved with **Numpy** (which is implemented in C) to take **3 ms**.
495-
- Ended with **Rust** taking **1 ms**.
540+
- Ended with **Rust** taking **1 ms** (just like numba version).
496541
497542
In this example **Rust** performed **100x** faster than our **Pure Python**.
498543

0 commit comments

Comments
 (0)