Skip to content
This repository has been archived by the owner on Aug 30, 2019. It is now read-only.

Fix performance issue in quantile.WeighSummary #406

Merged
merged 4 commits into from
Apr 9, 2018
Merged

Conversation

bmermet
Copy link

@bmermet bmermet commented Apr 9, 2018

rand.Seed(7337) was called on every call to probabilisticRound which was both incorrect and very slow since it was equivalent to having a single hard coded float to do all the roundings and calls to rand.Seed are very expensive.

@bmermet bmermet requested a review from LotharSee April 9, 2018 12:40
rand.Seed(7337)
for i := 0; i < 100; i++ {
randomFloats = append(randomFloats, rand.Float64())
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May this be more efficient?

randomFloats = make([]float64, 100)
for i := 0; i < 100; i++ {
	randomFloats[i] = rand.Float64()
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, indeed 👍

func init() {
// generate a list of guaranteed random numbers for the probabilistic round
randomFloats = make([]float64, 100)
rand.Seed(7337)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: to not affect the global rand seed, we could use r:= New(NewSource(7337)) / r.Float64().

@bmermet bmermet merged commit 418e72a into master Apr 9, 2018
@bmermet bmermet deleted the bmermet/seed-optim branch April 9, 2018 16:16
@palazzem palazzem added this to the 6.1.3 milestone Apr 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants