run_lox_benches 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/usr/bin/env python3
  2. import os
  3. import re
  4. import subprocess
  5. import sys
  6. def run_bench(cmd):
  7. """Run the benchmark with the given command (passed as an array of
  8. arguments). The benchmark is expected to output on stdout one or more
  9. csv tables, of the form:
  10. === Table 5 ===
  11. protocol,request size,response size
  12. Open Invitation,249,543
  13. Trust Promotion,1677,2285
  14. Trust Migration,845,241
  15. Level Up,2253,241
  16. Issue Invite,1101,401
  17. Redeem Invite,1037,241
  18. Check Blockage,685,325
  19. Blockage Migration,973,241
  20. Update Invite,557,209
  21. Update Credential,749,209
  22. This function will return a dictionary with keys being the name of the
  23. table ("Table 5"), and the value being a list of csv rows, where each row
  24. is a dict with keys being the name of the column, and the value being the
  25. entry in that column."""
  26. proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, text=True)
  27. table_name = None
  28. seen_nonempty_line = False
  29. retval = {}
  30. table = []
  31. headers = []
  32. for line in proc.stdout:
  33. print(line,end='')
  34. line = line.rstrip()
  35. if matched := re.match(r'=== (.*) ===', line):
  36. if table_name is not None:
  37. # Store the previous table
  38. retval[table_name] = table
  39. table_name = matched.group(1)
  40. seen_nonempty_line = False
  41. table = []
  42. headers = []
  43. continue
  44. if line == "" and seen_nonempty_line == True:
  45. if table_name is not None:
  46. # The table is finished; store it
  47. retval[table_name] = table
  48. table_name = None
  49. seen_nonempty_line = False
  50. table = []
  51. headers = []
  52. continue
  53. if line == "":
  54. continue
  55. # At this point, we know the line is nonempty
  56. if len(headers) == 0:
  57. # This should be the header line
  58. headers = line.split(',')
  59. seen_nonempty_line = True
  60. else:
  61. values = line.split(',')
  62. row = dict(zip(headers, values))
  63. table.append(row)
  64. # If stdout ends, and there's a table in progress, store it
  65. if table_name is not None:
  66. retval[table_name] = table
  67. return retval
  68. os.chdir(os.path.dirname(os.path.realpath(sys.argv[0])))
  69. os.environ['PYTHONUNBUFFERED'] = '1'
  70. if len(sys.argv) > 1:
  71. niters = sys.argv[1]
  72. else:
  73. niters = "10"
  74. lox_sigma_native = run_bench(["./run_native_bench", niters])
  75. lox_zkp_native = run_bench(["./run_native_bench", "-z", niters])
  76. lox_sigma_wasm = run_bench(["./run_wasm_bench", niters])
  77. lox_zkp_wasm = run_bench(["./run_wasm_bench", "-z", niters])
  78. print("\n*** Complete Table 2 ***\n")
  79. print("protocol,zkp client native ms,zkp client wasm ms,zkp server native ms,sigma-rs client native ms,sigma-rs client wasm ms,sigma-rs server native ms")
  80. for r in range(len(lox_sigma_native['Table 2'])):
  81. proto = lox_sigma_native['Table 2'][r]['protocol']
  82. assert proto == lox_zkp_native['Table 2'][r]['protocol']
  83. assert proto == lox_sigma_wasm['Table 2'][r]['protocol']
  84. assert proto == lox_zkp_wasm['Table 2'][r]['protocol']
  85. print(','.join([
  86. proto,
  87. lox_zkp_native['Table 2'][r]['client native ms'],
  88. lox_zkp_wasm['Table 2'][r]['client wasm ms'],
  89. lox_zkp_native['Table 2'][r]['server native ms'],
  90. lox_sigma_native['Table 2'][r]['client native ms'],
  91. lox_sigma_wasm['Table 2'][r]['client wasm ms'],
  92. lox_sigma_native['Table 2'][r]['server native ms'],
  93. ]))
  94. print("\n*** Complete Table 5 ***\n")
  95. print("protocol,zkp request bytes,zkp response bytes,sigma-rs request bytes,sigma-rs response bytes")
  96. for r in range(len(lox_sigma_native['Table 5'])):
  97. proto = lox_sigma_native['Table 5'][r]['protocol']
  98. assert proto == lox_zkp_native['Table 5'][r]['protocol']
  99. print(','.join([
  100. proto,
  101. lox_zkp_native['Table 5'][r]['request size'],
  102. lox_zkp_native['Table 5'][r]['response size'],
  103. lox_sigma_native['Table 5'][r]['request size'],
  104. lox_sigma_native['Table 5'][r]['response size'],
  105. ]))