Last active
August 29, 2015 14:15
-
-
Save tilpner/d873559ba3a73ca3bc99 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo ' | |
#![feature(core)] | |
use std::num::Float; | |
fn is_prime(i: i32) -> bool { | |
for j in 2..(i as f32).sqrt() as i32 + 1 { | |
unsafe { std::intrinsics::assume(j != 0) } | |
if i % j == 0 { | |
return false; | |
} | |
} | |
return true; | |
} | |
fn main() { | |
let mut primes = 0i64; | |
for i in 2..10000000 { | |
if is_prime(i) { | |
primes += 1; | |
} | |
} | |
println!("{}", primes); | |
}' > primes.rs | |
echo ' | |
#include <stdio.h> | |
#include <math.h> | |
#include <stdbool.h> | |
bool is_prime(int i) { | |
int upper = ((int) sqrtf((int) i)) + 1; | |
int j; | |
for (j = 2; j < upper; ++j) { | |
if (i % j == 0) { | |
return false; | |
} | |
} | |
return true; | |
} | |
int main() { | |
int i; | |
long primes = 0; | |
for (i = 2; i < 10000000; ++i) { | |
if (is_prime(i)) { | |
primes++; | |
} | |
} | |
printf("%d\n", primes); | |
return 0; | |
}' > primes.c | |
rustc -C opt-level=3 -C lto --cfg ndebug -C no-stack-check -C no-redzone -o rustc_primes primes.rs | |
objcopy -S rustc_primes rustc_primes_strip | |
gcc -lm -O3 -flto -Bstatic -o gcc_primes primes.c | |
objcopy -S gcc_primes gcc_primes_strip | |
clang -lm -O3 -Bstatic -o clang_primes primes.c | |
objcopy -S clang_primes clang_primes_strip | |
echo "Rust: " | |
/usr/bin/time -v ./rustc_primes_strip | |
perf record -o rustc.dat ./rustc_primes | |
echo "Gcc: " | |
/usr/bin/time -v ./gcc_primes_strip | |
perf record -o gcc.dat ./gcc_primes | |
echo "Clang: " | |
/usr/bin/time -v ./clang_primes_strip | |
perf record -o clang.dat ./clang_primes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment