Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
T
trampoline-rs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
4
Snippets
Groups
Projects
Show more breadcrumbs
Timothy
trampoline-rs
Commits
84f6c843
Unverified
Commit
84f6c843
authored
6 years ago
by
Timothy
Browse files
Options
Downloads
Patches
Plain Diff
Add benchmark
parent
4d5163e0
No related branches found
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
README.md
+8
-0
8 additions, 0 deletions
README.md
benches/bench.rs
+18
-0
18 additions, 0 deletions
benches/bench.rs
src/lib.rs
+2
-0
2 additions, 0 deletions
src/lib.rs
src/oddness/mod.rs
+38
-0
38 additions, 0 deletions
src/oddness/mod.rs
tests/mutual.rs
+1
-30
1 addition, 30 deletions
tests/mutual.rs
with
67 additions
and
30 deletions
README.md
0 → 100644
+
8
−
0
View file @
84f6c843
Benchmarks against a straight loop
----------------------------------
$ lscpu | grep "Model name"
Model name: Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz
$ cargo bench
test bench_oddness ... bench: 398,832 ns/iter (+/- 261,575)
test bench_oddness_loop ... bench: 2 ns/iter (+/- 0)
This diff is collapsed.
Click to expand it.
benches/bench.rs
0 → 100644
+
18
−
0
View file @
84f6c843
#![feature(test)]
extern
crate
tramp
;
extern
crate
test
;
use
tramp
::
oddness
as
oddness
;
use
test
::
Bencher
;
#[bench]
fn
bench_oddness
(
b
:
&
mut
Bencher
)
{
let
mut
val
:
u128
=
1000
;
b
.iter
(||
{
oddness
::
is_even
(
val
);
val
+=
1
;});
}
#[bench]
fn
bench_oddness_loop
(
b
:
&
mut
Bencher
)
{
let
mut
val
:
u128
=
1000
;
b
.iter
(||
{
oddness
::
is_even_loop
(
val
);
val
+=
1
;});
}
This diff is collapsed.
Click to expand it.
src/lib.rs
+
2
−
0
View file @
84f6c843
...
...
@@ -180,3 +180,5 @@ macro_rules! rec_ret {
return
$crate
::
BorrowRec
::
Ret
(
$val
);
};
}
pub
mod
oddness
;
This diff is collapsed.
Click to expand it.
src/oddness/mod.rs
0 → 100644
+
38
−
0
View file @
84f6c843
use
super
::{
Rec
,
tramp
};
fn
is_even_rec
(
x
:
u128
)
->
Rec
<
bool
>
{
if
x
>
0
{
rec_call!
(
is_odd_rec
(
x
-
1
))
}
else
{
rec_ret!
(
true
)
}
}
fn
is_odd_rec
(
x
:
u128
)
->
Rec
<
bool
>
{
if
x
>
0
{
rec_call!
(
is_even_rec
(
x
-
1
))
}
else
{
rec_ret!
(
false
)
}
}
pub
fn
is_even
(
x
:
u128
)
->
bool
{
tramp
(
is_even_rec
(
x
))
}
pub
fn
is_odd
(
x
:
u128
)
->
bool
{
tramp
(
is_odd_rec
(
x
))
}
pub
fn
is_even_loop
(
x
:
u128
)
->
bool
{
let
mut
i
:
u128
=
x
;
let
mut
even
=
true
;
while
i
>
0
{
i
=
i
-
1
;
even
=
!
even
;
}
even
}
pub
fn
is_odd_loop
(
x
:
u128
)
->
bool
{
!
is_even_loop
(
x
)
}
This diff is collapsed.
Click to expand it.
tests/mutual.rs
+
1
−
30
View file @
84f6c843
#[macro_use]
extern
crate
tramp
;
// Not the greatest way of computing "is even" or "is odd".
mod
oddness
{
use
tramp
::{
tramp
,
Rec
};
fn
is_even_rec
(
x
:
u128
)
->
Rec
<
bool
>
{
if
x
>
0
{
rec_call!
(
is_odd_rec
(
x
-
1
))
}
else
{
rec_ret!
(
true
)
}
}
fn
is_odd_rec
(
x
:
u128
)
->
Rec
<
bool
>
{
if
x
>
0
{
rec_call!
(
is_even_rec
(
x
-
1
))
}
else
{
rec_ret!
(
false
)
}
}
pub
fn
is_even
(
x
:
u128
)
->
bool
{
tramp
(
is_even_rec
(
x
))
}
pub
fn
is_odd
(
x
:
u128
)
->
bool
{
tramp
(
is_odd_rec
(
x
))
}
}
use
tramp
::
oddness
;
#[test]
fn
test_oddness
()
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment