Open VincentLagerros opened 1 month ago
What were your Odin build settings?
What were your Odin build settings?
Not specified, only odin build .
Is there some release flag I am unaware of, because I don't find any in build -help
-o:speed
will produce an optimized Odin binary. odin help build
is the command you were looking for.
Just to make sure, try doing sys.stdout.flush()
after your print
in Python.
Printing in a test isn't a "benchmark" is not a good idea ever.
Neither printing nor -o:speed changes the result, it is still a magnitude slower. For reference when comparing py and odin I get odin: 14.502 s vs py: 1.206 s
on the same test.
I am also wondering if the python example is even doing big ints in the first place. Yes integers in Python can be big ints but they do a lot of optimizations to not use them until needed.
No, python cant optimize this with small integers as catlan numbers grow really large really fast. Just n=37 will use more than bits than can fit into a u64 and the code is calculating for n=60000. I have written my own bigint in rust that is very much inspired by num_bigint, and it does not have this problem either.
Just as an example how the stdlib of odin does not seam to be optimized the _itoa_raw_full does a a division by radix for every char.
This is way slower than dividing by radix^x where radix^x is the max number that can fit into DIGIT. Then you can take that digit and do regular mul/div to get like 10 digits per long division instead of 1.
https://github.com/rust-num/num-bigint/blob/master/src/biguint/convert.rs#L699
To be clear, we have not optimized the core:math/big
library whatsoever. It's a direct port of libTomMath with numerous bug fixes and improves to the original codebase.
I was just asking basic questions earlier because I wanted to see if you were actually testing the correct thing or not. It's not always obvious to tell.
Also, we accept high quality PRs that improve the status quo!
That makes sense, but I doubt I can do a high quality PR when I have only been programming in odin for a few hours. However I can say that if you guys want to implement a really fast big int, then take a look at rug/gmplib.
We can't. They're under the GPL.
Context
Expected Behavior
Fast big.mul big.div and big.int_itoa_string
Current Behavior
big.mul, big.div and big.int_itoa_string is an order of magnitude slower than they should be. Just comparing the generation of catlan numbers up to 20000 and python3 is 10x faster.
Failure Information (for bugs)
Steps to Reproduce
I wrote a solution to https://open.kattis.com/problems/catalan in both python3 and odin to compare. The logic should be the same, but odin is way slower both on my local machine and on the online judge.
Here is a basic testcase