-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCli.swift
More file actions
48 lines (45 loc) · 1.21 KB
/
Cli.swift
File metadata and controls
48 lines (45 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import ArgumentParser
import EthAddress
import Headers
@main
struct Main: AsyncParsableCommand {
@Argument(transform: { (s: String) -> pubkey in
guard let k = str2pubkey(s) else {
throw ValidationError("")
}
return k
})
var pubkey: pubkey
@Flag
var zero_bytes: Bool = false
@Flag
var leading_zeros: Bool = false
func run() async {
await Task { @MainActor in
var score = "leading_zeros"
if zero_bytes {
score = "zero_bytes"
}
let clock = ContinuousClock()
let start = clock.now
print("initializing...")
let it = Iterate(score: score, start: unsafeBitCast(pubkey, to: group_elem.self))
while true {
let elapsed = clock.measure {
let r = it.compute()
for ri in r {
print(ri.toString())
}
}
let s: Double =
Double(elapsed.components.seconds) + Double(elapsed.components.attoseconds)
/ 1_000_000_000_000_000_000
print(
"\u{1B}[2K\rtime: \(start.duration(to: clock.now)) "
+ "speed: \(Double(steps_per_thread * threads_per_grid) / s / 1000_000) M/s\r",
terminator: "")
fflush(stdout)
}
}.value
}
}