Add some benchmarks
This commit is contained in:
parent
4e4cad8a20
commit
d20f54bb1a
4 changed files with 99 additions and 4 deletions
|
@ -8,6 +8,7 @@ rust:
|
||||||
script:
|
script:
|
||||||
- rustup component add rust-src
|
- rustup component add rust-src
|
||||||
- cargo install xargo || echo "Skipping xargo install"
|
- cargo install xargo || echo "Skipping xargo install"
|
||||||
|
- cargo install hyperfine || echo "Skipping hyperfine install"
|
||||||
- ./prepare_libcore.sh
|
- ./prepare_libcore.sh
|
||||||
- ./build.sh
|
- ./build.sh
|
||||||
|
|
||||||
|
|
24
build.sh
24
build.sh
|
@ -48,13 +48,29 @@ SHOULD_RUN=1 $RUSTC --crate-type bin example/mini_core_hello_world.rs --cfg jit
|
||||||
echo "[AOT] mini_core_hello_world"
|
echo "[AOT] mini_core_hello_world"
|
||||||
build_example_bin mini_core_hello_world example/mini_core_hello_world.rs
|
build_example_bin mini_core_hello_world example/mini_core_hello_world.rs
|
||||||
|
|
||||||
echo "[BUILD] core"
|
|
||||||
time $RUSTC target/libcore/src/libcore/lib.rs --crate-type lib --crate-name core -Cincremental=target/incremental_core
|
|
||||||
|
|
||||||
pushd xargo
|
pushd xargo
|
||||||
rm -r ~/.xargo/HOST || true
|
rm -r ~/.xargo/HOST || true
|
||||||
rm -r target || true
|
rm -r target || true
|
||||||
time xargo build --color always
|
time xargo build
|
||||||
popd
|
popd
|
||||||
|
|
||||||
|
$RUSTC --sysroot ~/.xargo/HOST example/alloc_example.rs --crate-type bin
|
||||||
|
# TODO linux linker doesn't accept duplicate definitions
|
||||||
|
#gcc -Wl,--gc-sections target/out/alloc_example ~/.xargo/HOST/lib/rustlib/*/lib/libcore-*.rlib ~/.xargo/HOST/lib/rustlib/*/lib/liballoc-*.rlib ~/.xargo/HOST/lib/rustlib/*/lib/liballoc_system-*.rlib -o target/out/alloc_example_exe
|
||||||
|
#hyperfine ./target/out/alloc_example_exe
|
||||||
|
|
||||||
|
$RUSTC --sysroot ~/.xargo/HOST example/mod_bench.rs --crate-type bin
|
||||||
|
gcc -Wl,--gc-sections target/out/mod_bench -lc -o target/out/mod_bench_exe
|
||||||
|
|
||||||
|
$RUSTC --sysroot ~/.xargo/HOST example/mod_bench.rs --crate-type bin -Zmir-opt-level=3 --crate-name mod_bench_inline
|
||||||
|
gcc -Wl,--gc-sections target/out/mod_bench_inline -lc -o target/out/mod_bench_inline_exe
|
||||||
|
|
||||||
|
rustc example/mod_bench.rs --crate-type bin -Copt-level=0 -o target/out/mod_bench_llvm_0 -Cpanic=abort
|
||||||
|
rustc example/mod_bench.rs --crate-type bin -Copt-level=1 -o target/out/mod_bench_llvm_1 -Cpanic=abort
|
||||||
|
rustc example/mod_bench.rs --crate-type bin -Copt-level=2 -o target/out/mod_bench_llvm_2 -Cpanic=abort
|
||||||
|
rustc example/mod_bench.rs --crate-type bin -Copt-level=3 -o target/out/mod_bench_llvm_3 -Cpanic=abort
|
||||||
|
echo
|
||||||
|
echo "[Bench] mod_bench"
|
||||||
|
hyperfine ./target/out/mod_bench{,_inline}_exe ./target/out/mod_bench_llvm_*
|
||||||
|
|
||||||
cat target/out/log.txt | sort | uniq -c
|
cat target/out/log.txt | sort | uniq -c
|
||||||
|
|
41
example/alloc_example.rs
Normal file
41
example/alloc_example.rs
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
#![feature(start, box_syntax, alloc_system, core_intrinsics, alloc, alloc_error_handler)]
|
||||||
|
#![no_std]
|
||||||
|
|
||||||
|
extern crate alloc;
|
||||||
|
extern crate alloc_system;
|
||||||
|
|
||||||
|
use alloc::prelude::*;
|
||||||
|
|
||||||
|
use alloc_system::System;
|
||||||
|
|
||||||
|
#[global_allocator]
|
||||||
|
static ALLOC: System = System;
|
||||||
|
|
||||||
|
#[link(name = "c")]
|
||||||
|
extern "C" {
|
||||||
|
fn puts(s: *const u8);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[panic_handler]
|
||||||
|
fn panic_handler(_: &core::panic::PanicInfo) -> ! {
|
||||||
|
unsafe {
|
||||||
|
core::intrinsics::abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[alloc_error_handler]
|
||||||
|
fn alloc_error_handler(_: alloc::alloc::Layout) -> ! {
|
||||||
|
unsafe {
|
||||||
|
core::intrinsics::abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[start]
|
||||||
|
fn main(_argc: isize, _argv: *const *const u8) -> isize {
|
||||||
|
let world: Box<&str> = box "Hello World!\0";
|
||||||
|
unsafe {
|
||||||
|
puts(*world as *const str as *const u8);
|
||||||
|
}
|
||||||
|
|
||||||
|
0
|
||||||
|
}
|
37
example/mod_bench.rs
Normal file
37
example/mod_bench.rs
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
#![feature(start, box_syntax, core_intrinsics, lang_items)]
|
||||||
|
#![no_std]
|
||||||
|
|
||||||
|
#[link(name = "c")]
|
||||||
|
extern {}
|
||||||
|
|
||||||
|
#[panic_handler]
|
||||||
|
fn panic_handler(_: &core::panic::PanicInfo) -> ! {
|
||||||
|
unsafe {
|
||||||
|
core::intrinsics::abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[lang="eh_personality"]
|
||||||
|
fn eh_personality(){}
|
||||||
|
|
||||||
|
// Required for rustc_codegen_llvm
|
||||||
|
#[no_mangle]
|
||||||
|
unsafe extern "C" fn _Unwind_Resume() {
|
||||||
|
core::intrinsics::unreachable();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[start]
|
||||||
|
fn main(_argc: isize, _argv: *const *const u8) -> isize {
|
||||||
|
for i in 2..100_000_000 {
|
||||||
|
black_box((i + 1) % i);
|
||||||
|
}
|
||||||
|
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(never)]
|
||||||
|
fn black_box(i: u32) {
|
||||||
|
if i != 1 {
|
||||||
|
unsafe { core::intrinsics::abort(); }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue