Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2)

Issue 4573041: big: Improved speed of big-to-string conversion for printing

Can't Edit
Can't Publish+Mail
Start Review
Created:
14 years, 5 months ago by mtj
Modified:
14 years, 5 months ago
Reviewers:
gri
CC:
golang-dev
Visibility:
Public.

Description

big: Improved speed of big-to-string conversion for printing Three optimizations: First, special-case power of two bases that partion a Word(), bases 2, 4, 16, and 256. These can be moved directly from internal Word() storage to the output without multiprecision operations. Next, same approach for the other power-of-two bases, 8, 32, 64, and 128. These don't fill a Word() evenly, so special handling is needed for those cases where input spans the high-bits of one Word and the low bis of the next one. Finally, implement the general case for others bases in 2 <= base <= 256 using superbases, the largest power of base representable in a Word(). For base ten, this is 9 digits and a superbase of 10^9 for 32-bit Words and 19 digits and 10^19 for 64-bit compiles. This way we do just 1/9th or 1/19th of the expensive multiprecision divisions, unpacking superdigits using fast native machine arithmetic. Speedups compared to the previous version range from 200x the rate (hexadadecimal) down to 17x for decimal in 64 bit, and faster still (relatively) in 32-bit since the multi- precision code is not as tuned there.

Patch Set 1 #

Patch Set 2 : diff -r fa2bae213af8 https://go.googlecode.com/hg/ #

Total comments: 57
Unified diffs Side-by-side diffs Delta from patch set Stats (+185 lines, -47 lines) Patch
M src/pkg/big/nat.go View 1 7 chunks +185 lines, -47 lines 57 comments Download

Messages

Total messages: 3
gri
Very nice. Lots of comments, but mostly on the use of variable names. I tried ...
14 years, 5 months ago (2011-06-03 22:56:46 UTC) #1
mtj
Wow, so wonderfully assistive! Thanks! I did all but three of the suggested changes. Details ...
14 years, 5 months ago (2011-06-04 08:21:42 UTC) #2
mtj
14 years, 5 months ago (2011-06-04 19:19:53 UTC) #3
I also added benchmark tests for bases 2, 8, 10, and 16. Here are the results with the old code: mtj-macbookpro:big mtj$ make bench gotest -test.bench=. -test.run="Do not run tests" rm -f _test/big.a rm -f _test/big.a gopack grc _test/big.a _gotest_.6 arith_amd64.6 PASS big.BenchmarkHilbert 500 5833338 ns/op big.BenchmarkBitset	20000000 132 ns/op big.BenchmarkBitsetNeg	10000000 240 ns/op big.BenchmarkBitsetOrig 5000000 606 ns/op big.BenchmarkBitsetNegOrig 1000000 1029 ns/op big.BenchmarkMul 500 3193490 ns/op big.BenchmarkScanPi 10000 243586 ns/op big.BenchmarkString2 10 137214700 ns/op big.BenchmarkString8 50 61214940 ns/op big.BenchmarkString10 50 56151740 ns/op big.BenchmarkString16 50 47801960 ns/op ...and with the new... mtj-macbookpro:big mtj$ make bench gotest -test.bench=. -test.run="Do not run tests" rm -f _test/big.a rm -f _test/big.a gopack grc _test/big.a _gotest_.6 arith_amd64.6 PASS big.BenchmarkHilbert 500 5823440 ns/op big.BenchmarkBitset	20000000 133 ns/op big.BenchmarkBitsetNeg	10000000 238 ns/op big.BenchmarkBitsetOrig 5000000 601 ns/op big.BenchmarkBitsetNegOrig 1000000 1029 ns/op big.BenchmarkMul 500 3190486 ns/op big.BenchmarkScanPi 10000 243989 ns/op big.BenchmarkString2 10000 203773 ns/op big.BenchmarkString8 50000 72232 ns/op big.BenchmarkString10 500 3124502 ns/op big.BenchmarkString16 50000 53168 ns/op ...the speedups are notable. "%b" = 673x "%o" = 847x "%d" = 17x "%x" = 899x
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b