Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unneeded double initialization in Random class>>seed: #17510

Open
tinchodias opened this issue Dec 10, 2024 · 0 comments
Open

Unneeded double initialization in Random class>>seed: #17510

tinchodias opened this issue Dec 10, 2024 · 0 comments

Comments

@tinchodias
Copy link
Contributor

Instances of Random have a seed. The seed can be explicitly set on creation (via seed:), or it can be generated from current timestamp (via new). I wanted to see how much slower is to generate the seed, so wrote this benchmark:

{
[ Random new ].
[ Random seed: 7 ].
} collect: #bench.

But discovered that new was faster than seed:, and it doesn't make sense:

  • new: 549,165 per second
  • seed: 295,684 per second

What happens is that Random seed: 7 first initializes the instance with a timestamp-based seed, and immediately after overrides it with the explicitly set.

This is in Pharo 12 and 13. I have a PR to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant