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

[BUG] random.random_float64 is extremely slow #2388

Open
ma-sadeghi opened this issue Apr 23, 2024 · 0 comments
Open

[BUG] random.random_float64 is extremely slow #2388

ma-sadeghi opened this issue Apr 23, 2024 · 0 comments
Labels
bug Something isn't working mojo Issues that are related to mojo mojo-repo Tag all issues with this label mojo-stdlib Tag for issues related to standard library

Comments

@ma-sadeghi
Copy link

Bug description

Generating one random number at a time in a for loop is extremely slow, almost 2 orders of magnitude slower than a numba-jitted equivalent.

Context: I tried to use a simple Monte Carlo approach to calculate Pi by generating two random numbers in a box one at a time and checking whether they are inside the inscribed circle.

Steps to reproduce

fn calc_pi(n: Int) -> Float64:
    """Computes pi using Monte Carlo method."""
    var j: Int = 0
    var x: Float64
    var y: Float64

    for i in range(n):
        x = random.random_float64()
        y = random.random_float64()
        if pow(x, 2) + pow(y, 2) <= 1.0:
            j += 1

    var pi: Float64 = 4.0 * j / n
    return pi

System information

- What OS did you do install Mojo on ? Ubuntu 22.04
- Provide version information for Mojo by pasting the output of `mojo -v` mojo 24.2.1 (58157dc0)
- Provide Modular CLI version by pasting the output of `modular -v` modular 0.7.2 (d0adc668)
@ma-sadeghi ma-sadeghi added bug Something isn't working mojo Issues that are related to mojo labels Apr 23, 2024
@ematejska ematejska added the mojo-repo Tag all issues with this label label Apr 29, 2024
@ematejska ematejska added the mojo-stdlib Tag for issues related to standard library label May 3, 2024 — with Linear
@ematejska ematejska removed the mojo-stdlib Tag for issues related to standard library label May 6, 2024
@ematejska ematejska added the mojo-stdlib Tag for issues related to standard library label May 6, 2024 — with Linear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mojo Issues that are related to mojo mojo-repo Tag all issues with this label mojo-stdlib Tag for issues related to standard library
Projects
None yet
Development

No branches or pull requests

2 participants