run_native_bench 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/usr/bin/env python3
  2. # Usage: ./run_native_bench [-z] [niters]
  3. # Use -z to benchmark the legacy zkp code; otherwise benchmark our sigma-rs code
  4. # niters defaults to 10
  5. import os
  6. import re
  7. import subprocess
  8. import sys
  9. progname = sys.argv.pop(0)
  10. if len(sys.argv) > 0 and sys.argv[0] == "-z":
  11. sys.argv.pop(0)
  12. loxdir = "../application-lox-zkp/crates/lox-library"
  13. cargo_features = "--features=bridgeauth"
  14. else:
  15. loxdir = "../application-lox/crates/lox-extensions"
  16. cargo_features = "--features=bridgeauth,test"
  17. if len(sys.argv) > 0:
  18. niters = sys.argv[0]
  19. else:
  20. niters = "10"
  21. os.environ['LOX_BENCH_NITERS'] = niters
  22. os.chdir(os.path.dirname(os.path.realpath(progname)))
  23. os.chdir(loxdir)
  24. proc = subprocess.Popen(["cargo", "test", "--release", "bench_",
  25. cargo_features, "--", "--nocapture", "--test-threads", "1"],
  26. stdout=subprocess.PIPE, text=True)
  27. protocol = None
  28. protocol_map = {
  29. 'BLOCKAGE-MIGRATION': 'Blockage Migration',
  30. 'CHECK-BLOCKAGE': 'Check Blockage',
  31. 'ISSUE-INVITATION': 'Issue Invite',
  32. 'LEVEL-UP-2: 44 days': 'Level Up',
  33. 'TRUST-MIGRATION-0: 30 days': 'Trust Migration',
  34. 'OPEN-INVITATION': 'Open Invitation',
  35. 'REDEEM-INVITATION': 'Redeem Invite',
  36. 'TRUST-PROMOTION-1: 30 days': 'Trust Promotion',
  37. 'UPDATE-CRED': 'Update Credential',
  38. 'UPDATE-INVITE': 'Update Invite',
  39. }
  40. req_size = {}
  41. resp_size = {}
  42. client_time = {}
  43. server_time = {}
  44. for line in proc.stdout:
  45. print(line,end='')
  46. if matched := re.match(r'----(.*)----', line):
  47. protocol = protocol_map[matched.group(1)]
  48. continue
  49. if matched := re.match(r'Request bytes range: \[\d+, (\d+)\]', line):
  50. req_size[protocol] = matched.group(1)
  51. elif matched := re.match(r'Response bytes range: \[\d+, (\d+)\]', line):
  52. resp_size[protocol] = matched.group(1)
  53. elif matched := re.match(r'Total client ms: ([\.\d]+) ± ([\.\d]+)', line):
  54. client_time[protocol] = (matched.group(1), matched.group(2))
  55. elif matched := re.match(r'Response ms: ([\.\d]+) ± ([\.\d]+)', line):
  56. server_time[protocol] = (matched.group(1), matched.group(2))
  57. # The order in which we output the protocols
  58. protocol_list = [
  59. 'Open Invitation',
  60. 'Trust Promotion',
  61. 'Trust Migration',
  62. 'Level Up',
  63. 'Issue Invite',
  64. 'Redeem Invite',
  65. 'Check Blockage',
  66. 'Blockage Migration',
  67. 'Update Invite',
  68. 'Update Credential',
  69. ]
  70. print("\n=== Table 2 ===\n")
  71. print("protocol,client native ms,server native ms")
  72. for p in protocol_list:
  73. print(f"{p},{client_time[p][0]} ({client_time[p][1]}),{server_time[p][0]} ({server_time[p][1]})")
  74. print("\n=== Table 5 ===\n")
  75. print("protocol,request size,response size")
  76. for p in protocol_list:
  77. print(f"{p},{req_size[p]},{resp_size[p]}")
  78. print()