DILSHAD737 commited on
Commit
b0ff3d4
·
1 Parent(s): cd31d24

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -1,20 +1,23 @@
1
  import time
2
  from multiprocessing import Pool
3
 
4
- def work(n):
5
- # BIP39 PBKDF2 simulation
6
  from mnemonic import Mnemonic
7
  m = Mnemonic("english")
8
  phrase = "lesson cushion crane affair federal decline limb spend reunion chief cart zebra"
 
 
9
  for _ in range(n):
10
  m.to_seed(phrase)
11
- return n
 
12
 
13
  if __name__ == "__main__":
14
- for workers in [48, 96, 192]:
15
  with Pool(workers) as p:
16
- start = time.time()
17
- p.map(work, [10] * workers)
18
- elapsed = time.time() - start
19
- rate = (workers * 10) / elapsed
20
- print(f"{workers} workers: {rate:,.0f} phrases/sec")
 
 
1
  import time
2
  from multiprocessing import Pool
3
 
4
+ def work(args):
 
5
  from mnemonic import Mnemonic
6
  m = Mnemonic("english")
7
  phrase = "lesson cushion crane affair federal decline limb spend reunion chief cart zebra"
8
+ n = args
9
+ start = time.perf_counter()
10
  for _ in range(n):
11
  m.to_seed(phrase)
12
+ elapsed = time.perf_counter() - start
13
+ return n / elapsed # per-worker phrases per second
14
 
15
  if __name__ == "__main__":
16
+ for workers in [12, 24, 48, 96, 192]:
17
  with Pool(workers) as p:
18
+ # Har worker ko 50 calls do (batch size)
19
+ rates = p.map(work, [50] * workers)
20
+ avg_rate = sum(rates) / len(rates)
21
+ total_rate = avg_rate * workers
22
+ print(f"{workers:3d} workers: {total_rate:,.0f} phrases/sec total "
23
+ f"({avg_rate:,.0f}/worker)")