Skip to content

Instantly share code, notes, and snippets.

@polachok
Created February 11, 2016 15:57
Show Gist options
  • Save polachok/e64f1911d49c670fb9cf to your computer and use it in GitHub Desktop.
Save polachok/e64f1911d49c670fb9cf to your computer and use it in GitHub Desktop.
ultrabench
root@c08fc12e0e0a:/bench# time ./test-c
9999010000
real 0m2.117s
user 0m1.463s
sys 0m0.652s
root@c08fc12e0e0a:/bench# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/5.3.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /usr/src/gcc/configure --disable-multilib --enable-languages=c,c++,go
Thread model: posix
gcc version 5.3.0 (GCC)
root@616e056b8d86:/bench# swiftc -O -o test-swift ./test.swift
root@616e056b8d86:/bench# time ./test-swift
9999010000
real 0m5.969s
user 0m5.287s
sys 0m0.675s
root@616e056b8d86:/bench# swiftc --version
Swift version 2.2-dev (LLVM 46be9ff861, Clang 4deb154edc, Swift 778f82939c)
Target: x86_64-unknown-linux-gnu
root@5823424123c8:/bench# go build -o test-go bench.go
root@5823424123c8:/bench# time ./test-go
9999010000
real 0m4.837s
user 0m7.686s
sys 0m0.563s
root@5823424123c8:/bench# go version
go version go1.6rc2 linux/amd64
[~/r]% rustc -O bench.rs -o test-rust
[~/r]% time ./test-rust
9999010000
real 0m1.000s
user 0m0.635s
sys 0m0.363s
[~/r]% rustc --version
rustc 1.6.0 (c30b771ad 2016-01-19)
@polachok
Copy link
Author

fn main() {
    let mut sum: i64 = 0;

    for _ in 0..200 {
        sum = 0;

        let mut x = vec![];
        for i in 0..1000000 {
            x.push(i);
        }

        let mut y = vec![];
        for i in 0..1000000-1 {
            y.push(x[i] + x[i+1]);
        }

        let mut i = 0;
        while i < 1000000 {
            sum += y[i];
            i += 100;
        }
    }
    println!("{}", sum);
}

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