11extern crate pyroscope;
22
33use pyroscope:: { PyroscopeAgent , Result } ;
4+ use std:: hash:: { Hash , Hasher } ;
45
5- fn fibonacci1 ( n : u64 ) -> u64 {
6- match n {
7- 0 | 1 => 1 ,
8- n => fibonacci1 ( n - 1 ) + fibonacci1 ( n - 2 ) ,
6+ fn hash_rounds1 ( n : u64 ) -> u64 {
7+ let hash_str = "Some string to hash" ;
8+ let mut default_hasher = std:: collections:: hash_map:: DefaultHasher :: new ( ) ;
9+
10+ for _ in 0 ..n {
11+ for _ in 0 ..1000 {
12+ default_hasher. write ( hash_str. as_bytes ( ) ) ;
13+ }
14+ hash_str. hash ( & mut default_hasher) ;
915 }
16+
17+ n
1018}
1119
12- fn fibonacci2 ( n : u64 ) -> u64 {
13- match n {
14- 0 | 1 => 1 ,
15- n => fibonacci2 ( n - 1 ) + fibonacci2 ( n - 2 ) ,
20+ fn hash_rounds2 ( n : u64 ) -> u64 {
21+ let hash_str = "Some string to hash" ;
22+ let mut default_hasher = std:: collections:: hash_map:: DefaultHasher :: new ( ) ;
23+
24+ for _ in 0 ..n {
25+ for _ in 0 ..1000 {
26+ default_hasher. write ( hash_str. as_bytes ( ) ) ;
27+ }
28+ hash_str. hash ( & mut default_hasher) ;
1629 }
30+
31+ n
1732}
1833
1934#[ tokio:: main]
@@ -26,14 +41,14 @@ async fn main() -> Result<()> {
2641 agent. start ( ) ?;
2742
2843 tokio:: task:: spawn ( async {
29- let n = fibonacci1 ( 45 ) ;
44+ let n = hash_rounds1 ( 300_000 ) ;
3045 println ! ( "Thread 1: {}" , n) ;
3146 } )
3247 . await
3348 . unwrap ( ) ;
3449
3550 tokio:: task:: spawn ( async {
36- let n = fibonacci2 ( 45 ) ;
51+ let n = hash_rounds2 ( 300_000 ) ;
3752 println ! ( "Thread 2: {}" , n) ;
3853 } )
3954 . await
0 commit comments