You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
391 B
Rust
28 lines
391 B
Rust
#![feature(test)]
|
|
|
|
extern crate test;
|
|
|
|
pub fn get_fact(n: u64) -> u64 {
|
|
if n < 2 {
|
|
1
|
|
} else {
|
|
n * get_fact(n - 1)
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use test::Bencher;
|
|
|
|
#[test]
|
|
fn it_works() {
|
|
assert_eq!(120, get_fact(5));
|
|
}
|
|
|
|
#[bench]
|
|
fn bench_get_fact(b: &mut Bencher) {
|
|
b.iter(|| get_fact(1234571));
|
|
}
|
|
}
|