Ver código fonte

Timing done. Not conditional yet...

themultiplexer 8 anos atrás
pai
commit
5401149b38
1 arquivos alterados com 11 adições e 0 exclusões
  1. 11
    0
      hw7/task1/src/main.rs

+ 11
- 0
hw7/task1/src/main.rs Ver arquivo

1
 extern crate clap;
1
 extern crate clap;
2
 extern crate time;
2
 extern crate time;
3
+
4
+use time::get_time;
3
 use clap::{Arg, App, SubCommand};
5
 use clap::{Arg, App, SubCommand};
4
 use std::process;
6
 use std::process;
5
 mod hasher_sha256;
7
 mod hasher_sha256;
9
     let matches = create_app().get_matches();
11
     let matches = create_app().get_matches();
10
     let base = matches.value_of("base").unwrap_or("1");
12
     let base = matches.value_of("base").unwrap_or("1");
11
     let diff = matches.value_of("difficulty").unwrap_or("1");
13
     let diff = matches.value_of("difficulty").unwrap_or("1");
14
+    let mut time_measurement = false;
12
 
15
 
13
     println!("Using base: {}", base);
16
     println!("Using base: {}", base);
14
     println!("Using difficulty: {}", diff);
17
     println!("Using difficulty: {}", diff);
18
         process::exit(1)
21
         process::exit(1)
19
     }
22
     }
20
 
23
 
24
+    if let Some(_) = matches.subcommand {
25
+        time_measurement = true;
26
+    }
27
+
21
     match base.parse::<usize>() {
28
     match base.parse::<usize>() {
22
         Ok(b) => {
29
         Ok(b) => {
23
             println!("Please wait...");
30
             println!("Please wait...");
31
+            let start = get_time();
24
             for n in 0..<usize>::max_value() {
32
             for n in 0..<usize>::max_value() {
25
                 if let Some(x) = hash256::verify_product(b, n, &diff.to_string()) {
33
                 if let Some(x) = hash256::verify_product(b, n, &diff.to_string()) {
34
+                    let end = get_time();
35
+                    let diff = end - start;
26
                     println!("Number: {} --> hash: {}", x.number, x.hash);
36
                     println!("Number: {} --> hash: {}", x.number, x.hash);
37
+                    println!("(Duration {}s / {}ms / {}us)", diff.num_seconds(), diff.num_milliseconds(), diff.num_microseconds().unwrap_or(0));
27
                     process::exit(0)
38
                     process::exit(0)
28
                 }
39
                 }
29
             }
40
             }

Carregando…
Cancelar
Salvar