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

Issue 21030043: code review 21030043: math/rand: minor optimization to Perm (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
12 years, 5 months ago by josharian
Modified:
12 years, 3 months ago
Reviewers:
adg, dave
CC:
golang-dev, dave_cheney.net, mtj1, adg
Visibility:
Public.

Description

math/rand: minor optimization to Perm Instead of writing out 0..n and then reading it back, just use i when it is needed. Wikipedia calls this the "inside-out" implementation: http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle This yields identical values to the previous implementation, given the same seed. (Note that the output from Example_rand is unchanged.) 2.8 GHz Intel Core i7, results very stable: benchmark old ns/op new ns/op delta BenchmarkPerm3 138 136 -1.45% BenchmarkPerm30 825 803 -2.67% Stock Raspberry Pi, minimum improvement out of three runs: benchmark old ns/op new ns/op delta BenchmarkPerm3 5774 5664 -1.91% BenchmarkPerm30 32582 29381 -9.82%

Patch Set 1 #

Patch Set 2 : diff -r 352f3b7c9664 https://code.google.com/p/go #

Patch Set 3 : diff -r 24bc2c8febe3 https://code.google.com/p/go #

Patch Set 4 : diff -r 24bc2c8febe3 https://code.google.com/p/go #

Patch Set 5 : diff -r 24bc2c8febe3 https://code.google.com/p/go #

Patch Set 6 : diff -r 4ce5fd769c69 https://code.google.com/p/go #

Unified diffs Side-by-side diffs Delta from patch set Stats (+16 lines, -4 lines) Patch
M src/pkg/math/rand/rand.go View 1 2 3 4 5 1 chunk +2 lines, -4 lines 0 comments Download
M src/pkg/math/rand/rand_test.go View 1 1 chunk +14 lines, -0 lines 0 comments Download

Messages

Total messages: 12
josharian
Hello golang-dev@googlegroups.com, I'd like you to review this change to https://code.google.com/p/go
12 years, 3 months ago (2013-12-14 02:21:02 UTC) #1
dave_cheney.net
On 2013/12/14 02:21:02, josharian wrote: > Hello mailto:golang-dev@googlegroups.com, > > I'd like you to review ...
12 years, 3 months ago (2013-12-14 02:24:31 UTC) #2
josharian
> Could you please test this on 386 or arm. Absolutely. I've updated the description ...
12 years, 3 months ago (2013-12-14 22:19:17 UTC) #3
dave_cheney.net
On 2013/12/14 22:19:17, josharian wrote: > > Could you please test this on 386 or ...
12 years, 3 months ago (2013-12-14 23:55:36 UTC) #4
mtj1
Dave, I understand that this is not intended as a "math/logic" change, just a cache-friendly ...
12 years, 3 months ago (2013-12-15 12:19:31 UTC) #5
mtj1
strike the part about the optimization. that's a dumb mental mistake. all the rest stands ...
12 years, 3 months ago (2013-12-15 12:21:17 UTC) #6
josharian
> In any case, every reader of this code will puzzle over this > to ...
12 years, 3 months ago (2013-12-15 16:45:19 UTC) #7
adg
LGTM But wait for some consensus I guess
12 years, 3 months ago (2013-12-15 21:35:30 UTC) #8
mtj1
This looks fine to me. It works and it's meaning makes clear that what is ...
12 years, 3 months ago (2013-12-16 15:33:55 UTC) #9
josharian
Ok, I've incorporated Michael's suggestion, and Dave's worries are allayed. Andrew, is this sufficient consensus? ...
12 years, 3 months ago (2013-12-17 02:10:56 UTC) #10
adg
On 17 December 2013 13:10, <josharian@gmail.com> wrote: > Ok, I've incorporated Michael's suggestion, and Dave's ...
12 years, 3 months ago (2013-12-17 02:15:49 UTC) #11
adg
12 years, 3 months ago (2013-12-17 02:49:53 UTC) #12
*** Submitted as https://code.google.com/p/go/source/detail?r=8ef815dd2770 ***

math/rand: minor optimization to Perm

Instead of writing out 0..n and then reading it
back, just use i when it is needed.

Wikipedia calls this the "inside-out" implementation:
http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle

This yields identical values to the previous
implementation, given the same seed. (Note that the
output from Example_rand is unchanged.)

2.8 GHz Intel Core i7, results very stable:

benchmark          old ns/op    new ns/op    delta
BenchmarkPerm3           138          136   -1.45%
BenchmarkPerm30          825          803   -2.67%

Stock Raspberry Pi, minimum improvement out of three runs:

benchmark          old ns/op    new ns/op    delta
BenchmarkPerm3          5774         5664   -1.91%
BenchmarkPerm30        32582        29381   -9.82%

R=golang-dev, dave, mtj, adg
CC=golang-dev
https://codereview.appspot.com/21030043

Committer: Andrew Gerrand <adg@golang.org>
Sign in to reply to this message.

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