-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
122 additions
and
21 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,6 @@ target/ | |
lcov.info | ||
|
||
build_artifacts/ | ||
|
||
*.so | ||
*.a |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bench_* | ||
*.so |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
cd "$(dirname "$0")" | ||
|
||
RED='\033[0;31m' | ||
NC='\033[0m' # No Color | ||
|
||
# name without extension, num_iters, input number | ||
function bench_program() { | ||
local name=$1 | ||
local num_iters=$2 | ||
local input=$3 | ||
|
||
echo -e "### ${RED}Benchmarking $name ${NC}" | ||
|
||
rustc --crate-type=cdylib "$name.rs" -C opt-level=3 -o "${name}_rs.so" > /dev/null 2>&1 | ||
cargo r -- "$name.con" --library --release > /dev/null 2>&1 | ||
cp "./build_artifacts/$name.so" "${name}_con.so" | ||
|
||
cc bench.c -L . -l:./"${name}"_rs.so -l:./"${name}"_con.so -Wl,-rpath -o bench_"${name}" | ||
|
||
./bench_"${name}" "$num_iters" "$input" | ||
} | ||
|
||
bench_program "factorial" 5000000 20 | ||
bench_program "fib" 5000 20 | ||
|
||
rm ./*.so |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
mod Factorial { | ||
fn factorial_concrete(n: u64) -> u64 { | ||
fn concrete_function(n: u64) -> u64 { | ||
if n == 0 { | ||
return 1; | ||
} else { | ||
return n * factorial_concrete(n - 1); | ||
return n * concrete_function(n - 1); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#[no_mangle] | ||
pub extern "C" fn rust_function(n: u64) -> u64 { | ||
if n == 0 { | ||
return 1; | ||
} else { | ||
return n * rust_function(n - 1); | ||
} | ||
} |
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
mod Fibonacci { | ||
pub fn concrete_function(n: u64) -> u64 { | ||
if n < 2 { | ||
return n; | ||
} | ||
|
||
return concrete_function(n - 1) + concrete_function(n - 2); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#[no_mangle] | ||
pub extern "C" fn rust_function(n: u64) -> u64 { | ||
if n < 2 { | ||
return n; | ||
} | ||
|
||
return rust_function(n - 1) + rust_function(n - 2); | ||
} |