Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upOptimize Int to String conversions [code inside] #26578
Comments
steveklabnik
added
the
I-slow
label
Jun 26, 2015
This comment has been minimized.
This comment has been minimized.
|
Will submit a PR latter today. |
arthurprs
closed this
Jul 18, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
arthurprs commentedJun 25, 2015
As of today rust uses a naive implementation for converting integers to decimal strings in Int Debug/Display methods.
I spent some time crafting an optimized version for the most commonly used case, that is, printing as decimals. This should be non measurable in most programs but might give us a minor speedup on some cases like serde and rustc json serializers.
I wrote a well optimized version here. Further optimizations are possible but I tried to keep the code size small (which I think is important), it's a road of diminished gains.
Running with rustc 1.2.0-nightly (cffaf0e 2015-06-23) @ x64 Linux - Intel(R) Core(TM) i7-2670QM @ 2.20Ghz (My notebook CPU)
Running with rustc 1.3.0-nightly (e5a28bc 2015-06-25) @ x86 Linux - Intel(R) Xeon(R) CPU E5-2650 0 @ 2.00GHz (EC2 c1.medium)
On modern x64 CPUs it's pretty much the same speed as the stdlib implementation for very small numbers, but pulls ahead as the length of the decimal increases.
On slight older CPUs (worse ALUs) or x86 it's pretty much always faster.
Is this something we want into the stdlib?
Follow up of #26310
marking @llogiq because of previous interest
marking @lifthrasiir because of the awesome work on similar stuff