|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+#[macro_use]
|
|
1
|
2
|
extern crate clap;
|
|
2
|
3
|
extern crate time;
|
|
3
|
4
|
extern crate task1;
|
|
|
@@ -5,13 +6,14 @@ extern crate sys_info;
|
|
5
|
6
|
|
|
6
|
7
|
use std::sync::mpsc::channel;
|
|
7
|
8
|
use time::get_time;
|
|
8
|
|
-use clap::{Arg, App, SubCommand};
|
|
|
9
|
+use clap::App;
|
|
9
|
10
|
use std::{process, thread};
|
|
10
|
11
|
use task1::verify_product;
|
|
11
|
12
|
use std::sync::Arc;
|
|
12
|
13
|
|
|
13
|
14
|
pub fn main() {
|
|
14
|
|
- let matches = create_app().get_matches();
|
|
|
15
|
+ let yaml = load_yaml!("cli.yml");
|
|
|
16
|
+ let matches = App::from_yaml(yaml).get_matches();
|
|
15
|
17
|
let base = matches.value_of("base").unwrap_or("1");
|
|
16
|
18
|
let diff = Arc::new(matches.value_of("difficulty").unwrap_or("1").to_string());
|
|
17
|
19
|
let cpus = sys_info::cpu_num().unwrap_or(1).to_string();
|
|
|
@@ -71,16 +73,7 @@ pub fn main() {
|
|
71
|
73
|
}
|
|
72
|
74
|
|
|
73
|
75
|
if let Some(solution) = verify_product(b, n, &d) {
|
|
74
|
|
- let end = get_time();
|
|
75
|
76
|
found = sync;
|
|
76
|
|
-
|
|
77
|
|
- if time_measurement {
|
|
78
|
|
- let diff = end - start;
|
|
79
|
|
- let s = diff.num_seconds();
|
|
80
|
|
- let ms = diff.num_milliseconds();
|
|
81
|
|
- let us = diff.num_microseconds().unwrap_or(ms * 1000);
|
|
82
|
|
- println!("(Duration {}s / {}ms / {}us)", s, ms, us);
|
|
83
|
|
- }
|
|
84
|
77
|
tx.send(solution).unwrap();
|
|
85
|
78
|
}
|
|
86
|
79
|
n += t;
|
|
|
@@ -91,7 +84,15 @@ pub fn main() {
|
|
91
|
84
|
|
|
92
|
85
|
match rx.recv() {
|
|
93
|
86
|
Ok(sol) => {
|
|
|
87
|
+ let end = get_time();
|
|
94
|
88
|
println!("Number: {} --> hash: {}", sol.number, sol.hash);
|
|
|
89
|
+ if time_measurement {
|
|
|
90
|
+ let diff = end - start;
|
|
|
91
|
+ let s = diff.num_seconds();
|
|
|
92
|
+ let ms = diff.num_milliseconds();
|
|
|
93
|
+ let us = diff.num_microseconds().unwrap_or(ms * 1000);
|
|
|
94
|
+ println!("(Duration {}s / {}ms / {}us)", s, ms, us);
|
|
|
95
|
+ }
|
|
95
|
96
|
}
|
|
96
|
97
|
Err(_) => {}
|
|
97
|
98
|
}
|
|
|
@@ -106,54 +107,3 @@ pub fn main() {
|
|
106
|
107
|
}
|
|
107
|
108
|
};
|
|
108
|
109
|
}
|
|
109
|
|
-
|
|
110
|
|
-fn create_app<'a, 'b>() -> App<'a, 'b> {
|
|
111
|
|
- App::new("Hash256")
|
|
112
|
|
- .version("1.0")
|
|
113
|
|
- .author("Lorenz Bung & Joshua Rutschmann")
|
|
114
|
|
- .about(
|
|
115
|
|
- "Calculates the Hashvalue of the given base, number and difficulty.",
|
|
116
|
|
- )
|
|
117
|
|
- .arg(
|
|
118
|
|
- Arg::with_name("base")
|
|
119
|
|
- .value_name("base")
|
|
120
|
|
- .help("Sets the base to use")
|
|
121
|
|
- .takes_value(true)
|
|
122
|
|
- .required(true),
|
|
123
|
|
- )
|
|
124
|
|
- .arg(
|
|
125
|
|
- Arg::with_name("difficulty")
|
|
126
|
|
- .value_name("difficulty")
|
|
127
|
|
- .help("Sets the difficulty to use")
|
|
128
|
|
- .takes_value(true)
|
|
129
|
|
- .required(true),
|
|
130
|
|
- )
|
|
131
|
|
- .arg(
|
|
132
|
|
- Arg::with_name("threads")
|
|
133
|
|
- .value_name("threads")
|
|
134
|
|
- .help(
|
|
135
|
|
- "Sets the number of the threads to use (default = number of cpus)",
|
|
136
|
|
- )
|
|
137
|
|
- .takes_value(true)
|
|
138
|
|
- .required(false),
|
|
139
|
|
- ).arg(Arg::with_name("verbose")
|
|
140
|
|
- .short("v")
|
|
141
|
|
- .multiple(true)
|
|
142
|
|
- .required(false),
|
|
143
|
|
- )
|
|
144
|
|
- .arg(Arg::with_name("sync")
|
|
145
|
|
- .short("s")
|
|
146
|
|
- .required(false),
|
|
147
|
|
- )
|
|
148
|
|
- .arg(Arg::with_name("config")
|
|
149
|
|
- .long("config")
|
|
150
|
|
- .value_name("VALUE")
|
|
151
|
|
- .help("sets special sync parameter")
|
|
152
|
|
- .takes_value(true))
|
|
153
|
|
- .subcommand(
|
|
154
|
|
- SubCommand::with_name("timings")
|
|
155
|
|
- .about("controls timing features")
|
|
156
|
|
- .version("1.0")
|
|
157
|
|
- .author("Lorenz Bung & Joshua Rutschmann"),
|
|
158
|
|
- )
|
|
159
|
|
-}
|