Giter Site home page Giter Site logo

Comments (2)

ebonnal avatar ebonnal commented on August 30, 2024

Added pypy's 30 times runtime improvement to the README

from streamable.

ebonnal avatar ebonnal commented on August 30, 2024

Few rough runtime orders of magnitude

Base snippet:

# main.py
from streamable import Stream
print(
    sum(
        Stream(range(1, 1_000_000_000))
        .map(lambda n: 1/n)
    )
)

interpreted by CPython

 % time python3 main.py
21.30048150134855
python3 main.py  102.75s user 0.09s system 99% cpu 1:43.61 total

interpreted by PyPy

% time pypy3 main.py
21.30048150134855
pypy3 main.py  2.12s user 0.02s system 99% cpu 2.162 total

Java stream

// Main.java
import java.util.stream.IntStream;
public class Main {
    public static void main(String[] args) {
        double sum = IntStream
            .range(1, 1_000_000_000)
            .mapToDouble(n -> 1.0 / n)
            .sum();
        System.out.println(sum);
    }
}
% javac Main.java
% time java -XX:+UseG1GC Main
21.300481501347942
java -XX:+UseG1GC Main  4.15s user 0.03s system 99% cpu 4.200 total

C for loop

// main.c
#include <stdio.h>
int main() {
    double sum = 0.0;
    for (long long int i = 1; i < 1000000000; ++i) {
        sum += 1.0 / i;
    }   
    printf("%.15f\n", sum);
    return 0;
}   
% gcc -O3 -o main_optimized.out main.c
% time ./main_optimized.out     
21.300481501348550
./main_optimized.out  1.02s user 0.00s system 99% cpu 1.034 total

Rust iterators

// main.rs
fn main() {
    let sum: f64 = (1..1_000_000_000)
        .map(|n| 1.0 / n as f64)
        .sum();
    println!("{}", sum);
}
% rustc -C opt-level=2 ./main.rs
% time ./main
21.30048150134855
./main  1.00s user 0.00s system 98% cpu 1.014 total

from streamable.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.