Skip to content

Instantly share code, notes, and snippets.

@Voultapher
Last active July 16, 2018 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Voultapher/7fbcf7e307896ea557b50eff5fb0db42 to your computer and use it in GitHub Desktop.
Save Voultapher/7fbcf7e307896ea557b50eff5fb0db42 to your computer and use it in GitHub Desktop.
rustc vs clang | llvm production | lib
pub fn foo(a: i64, b: i64) -> i64 {
(a % 239082) % b
}
pub fn bar(a: i64) -> i64 {
foo(a, 77)
}
#include <cstdint>
auto foo(int64_t a, int64_t b) -> int64_t
{
return (a % 239082) % b;
}
auto bar(int64_t a) -> int64_t
{
return foo(a, 77);
}
pub fn foo(a: i64, b: i64) -> i64 {
(a % 239082) % b
}
pub fn bar(a: i64) -> i64 {
foo(a, 77)
}
pub fn moop() {
std::process::exit(bar(std::env::args().len() as i64) as i32);
}

compiler | version

command

  • name | instruction count | time

clang++ | 6.0.1

perf stat clang++ -O3 -shared lib.cpp -o cpp-lib-full.so

  • full | 331m | 147ms

perf stat clang -O3 lib.cpp -emit-llvm -S -o cpp-lib.ll

  • emit | 218m | 95ms

perf stat llc -O3 -filetype=obj cpp-lib.ll -o cpp-lib.so

  • llvm compile | 56m | 45ms

rustc | 1.29.0-nightly

perf stat rustc -O --crate-type=lib lib.rs -o rust-lib-full.so

  • full | 549m | 200ms

perf stat rustc -O --crate-type=lib lib.rs --emit=llvm-ir -o rust-lib.ll

  • emit | 411m | 145ms

perf stat llc -O3 -filetype=obj rust-lib.ll -o rust-lib.so

  • llvm compile | 64m | 50ms

rustc | 1.29.0-nightly

perf stat rustc -O --crate-type=lib lib-min.rs -o rust-lib-min-full.so

  • full | 248m | 105ms

perf stat rustc -O --crate-type=lib lib-min.rs --emit=llvm-ir -o rust-lib-min.ll

  • emit | 231m | 90ms

perf stat llc -O3 -filetype=obj rust-lib-min.ll -o rust-lib-min.so

  • llvm compile | 54m | 44ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment