From aeb90927f0462946f068d8087c1bd6242edf223e Mon Sep 17 00:00:00 2001 From: Sh0g0-1758 Date: Sun, 23 Jun 2024 03:23:13 +0530 Subject: [PATCH 1/5] Added Benchmark for integration tests --- integration_tests/BenchMarks.txt | 13 +++++ integration_tests/cairozero_test.go | 76 +++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 integration_tests/BenchMarks.txt diff --git a/integration_tests/BenchMarks.txt b/integration_tests/BenchMarks.txt new file mode 100644 index 000000000..32cb2abf4 --- /dev/null +++ b/integration_tests/BenchMarks.txt @@ -0,0 +1,13 @@ +======================================================= +| File | PythonVM (ms) | GoVM (ms) | +======================================================= +| find_element.cairo | 609 | 100 | +| set_add.cairo | 748 | 105 | +| dict.cairo | 659 | 117 | +| fib.cairo | 706 | 104 | +| hintrefs.cairo | 657 | 111 | +| simple.cairo | 643 | 106 | +| squash_dict.cairo | 590 | 109 | +| alloc.cairo | 592 | 96 | +| factorial.cairo | 1143 | 110 | +======================================================= diff --git a/integration_tests/cairozero_test.go b/integration_tests/cairozero_test.go index 478c61186..a58330bfc 100644 --- a/integration_tests/cairozero_test.go +++ b/integration_tests/cairozero_test.go @@ -5,8 +5,10 @@ import ( "os" "os/exec" "path/filepath" + "strconv" "strings" "testing" + "time" "github.com/NethermindEth/cairo-vm-go/pkg/vm" "github.com/consensys/gnark-crypto/ecc/stark-curve/fp" @@ -57,6 +59,8 @@ func TestCairoZeroFiles(t *testing.T) { filter := Filter{} filter.init() + benchmarkMap := make(map[string][2]int) + for _, dirEntry := range testFiles { if dirEntry.IsDir() || isGeneratedFile(dirEntry.Name()) { continue @@ -76,18 +80,27 @@ func TestCairoZeroFiles(t *testing.T) { continue } + start := time.Now() + pyTraceFile, pyMemoryFile, err := runPythonVm(dirEntry.Name(), compiledOutput) if err != nil { t.Error(err) continue } + elapsed_py := time.Since(start) + + start = time.Now() + traceFile, memoryFile, _, err := runVm(compiledOutput) if err != nil { t.Error(err) continue } + elapsed_go := time.Since(start) + benchmarkMap[dirEntry.Name()] = [2]int{int(elapsed_py.Milliseconds()), int(elapsed_go.Milliseconds())} + pyTrace, pyMemory, err := decodeProof(pyTraceFile, pyMemoryFile) if err != nil { t.Error(err) @@ -110,9 +123,72 @@ func TestCairoZeroFiles(t *testing.T) { } } + WriteBenchMarksToFile(benchmarkMap) + clean(root) } +// Save the Benchmarks for the integration tests in `BenchMarks.txt` +func WriteBenchMarksToFile(benchmarkMap map[string][2]int) { + headers := []string{"File", "PythonVM (ms)", "GoVM (ms)"} + columnWidths := []int{20, 15, 10} + + totalWidth := 0 + for _, width := range columnWidths { + totalWidth += width + 3 + } + + totalWidth += 1 + + border := strings.Repeat("=", totalWidth) + + var sb strings.Builder + + sb.WriteString(border + "\n") + sb.WriteString(formatRow(headers, columnWidths) + "\n") + sb.WriteString(border + "\n") + + for key, values := range benchmarkMap { + row := []string{key} + for _, value := range values { + row = append(row, strconv.Itoa(value)) + } + sb.WriteString(formatRow(row, columnWidths) + "\n") + } + + sb.WriteString(border + "\n") + + fileName := "BenchMarks.txt" + file, err := os.Create(fileName) + if err != nil { + fmt.Println("Error creating file: ", err) + return + } + defer file.Close() + + _, err = file.WriteString(sb.String()) + if err != nil { + fmt.Println("Error writing to file: ", err) + } else { + fmt.Println("Benchmarks successfully written to:", fileName) + } +} + +// format a row with borders and spaces based on the column widths +func formatRow(row []string, widths []int) string { + var sb strings.Builder + sb.WriteString("|") + for i, col := range row { + sb.WriteString(" " + padRight(col, widths[i]) + " |") + } + return sb.String() +} + +// pad a string with spaces to the right to match the given width +func padRight(str string, width int) string { + return fmt.Sprintf("%-"+fmt.Sprintf("%d", width)+"s", str) +} + const ( compiledSuffix = "_compiled.json" pyTraceSuffix = "_py_trace" From b07a1171d8b495cb20162cabab37f514e9f3a040 Mon Sep 17 00:00:00 2001 From: Sh0g0-1758 Date: Tue, 25 Jun 2024 17:02:26 +0530 Subject: [PATCH 2/5] Relocated time measuring code --- integration_tests/BenchMarks.txt | 27 ++++++++-------- integration_tests/cairozero_test.go | 49 +++++++++++++++-------------- 2 files changed, 40 insertions(+), 36 deletions(-) diff --git a/integration_tests/BenchMarks.txt b/integration_tests/BenchMarks.txt index 32cb2abf4..45229d235 100644 --- a/integration_tests/BenchMarks.txt +++ b/integration_tests/BenchMarks.txt @@ -1,13 +1,14 @@ -======================================================= -| File | PythonVM (ms) | GoVM (ms) | -======================================================= -| find_element.cairo | 609 | 100 | -| set_add.cairo | 748 | 105 | -| dict.cairo | 659 | 117 | -| fib.cairo | 706 | 104 | -| hintrefs.cairo | 657 | 111 | -| simple.cairo | 643 | 106 | -| squash_dict.cairo | 590 | 109 | -| alloc.cairo | 592 | 96 | -| factorial.cairo | 1143 | 110 | -======================================================= +==================================================================== +| File | PythonVM (ms) | GoVM (ms) | +==================================================================== +| fib.cairo | 744 | 130 | +| squash_dict.cairo | 694 | 138 | +| set_add.cairo | 713 | 129 | +| simple.cairo | 729 | 124 | +| test.starknet_with_keccak.cairo | 1682 | 143 | +| alloc.cairo | 716 | 127 | +| dict.cairo | 714 | 123 | +| factorial.cairo | 1312 | 119 | +| find_element.cairo | 668 | 132 | +| hintrefs.cairo | 750 | 144 | +==================================================================== diff --git a/integration_tests/cairozero_test.go b/integration_tests/cairozero_test.go index a58330bfc..f33709904 100644 --- a/integration_tests/cairozero_test.go +++ b/integration_tests/cairozero_test.go @@ -80,25 +80,18 @@ func TestCairoZeroFiles(t *testing.T) { continue } - start := time.Now() - - pyTraceFile, pyMemoryFile, err := runPythonVm(dirEntry.Name(), compiledOutput) + elapsed_py, pyTraceFile, pyMemoryFile, err := runPythonVm(dirEntry.Name(), compiledOutput) if err != nil { t.Error(err) continue } - elapsed_py := time.Since(start) - - start = time.Now() - - traceFile, memoryFile, _, err := runVm(compiledOutput) + elapsed_go, traceFile, memoryFile, _, err := runVm(compiledOutput) if err != nil { t.Error(err) continue } - elapsed_go := time.Since(start) benchmarkMap[dirEntry.Name()] = [2]int{int(elapsed_py.Milliseconds()), int(elapsed_go.Milliseconds())} pyTrace, pyMemory, err := decodeProof(pyTraceFile, pyMemoryFile) @@ -131,7 +124,7 @@ func TestCairoZeroFiles(t *testing.T) { // Save the Benchmarks for the integration tests in `BenchMarks.txt` func WriteBenchMarksToFile(benchmarkMap map[string][2]int) { headers := []string{"File", "PythonVM (ms)", "GoVM (ms)"} - columnWidths := []int{20, 15, 10} + columnWidths := []int{33, 15, 10} totalWidth := 0 for _, width := range columnWidths { @@ -226,7 +219,7 @@ func compileZeroCode(path string) (string, error) { // given a path to a compiled cairo zero file, execute it using the // python vm and returns the trace and memory files location -func runPythonVm(testFilename, path string) (string, string, error) { +func runPythonVm(testFilename, path string) (time.Duration, string, string, error) { traceOutput := swapExtenstion(path, pyTraceSuffix) memoryOutput := swapExtenstion(path, pyMemorySuffix) @@ -251,19 +244,24 @@ func runPythonVm(testFilename, path string) (string, string, error) { cmd := exec.Command("cairo-run", args...) + start := time.Now() + res, err := cmd.CombinedOutput() + + elapsed := time.Since(start) + if err != nil { - return "", "", fmt.Errorf( + return 0, "", "", fmt.Errorf( "cairo-run %s: %w\n%s", path, err, string(res), ) } - return traceOutput, memoryOutput, nil + return elapsed, traceOutput, memoryOutput, nil } // given a path to a compiled cairo zero file, execute // it using our vm -func runVm(path string) (string, string, string, error) { +func runVm(path string) (time.Duration, string, string, string, error) { traceOutput := swapExtenstion(path, traceSuffix) memoryOutput := swapExtenstion(path, memorySuffix) @@ -290,14 +288,19 @@ func runVm(path string) (string, string, string, error) { path, ) + start := time.Now() + res, err := cmd.CombinedOutput() + + elapsed := time.Since(start) + if err != nil { - return "", "", string(res), fmt.Errorf( + return 0, "", "", string(res), fmt.Errorf( "cairo-vm run %s: %w\n%s", path, err, string(res), ) } - return traceOutput, memoryOutput, string(res), nil + return elapsed, traceOutput, memoryOutput, string(res), nil } @@ -376,7 +379,7 @@ func TestFailingRangeCheck(t *testing.T) { compiledOutput, err := compileZeroCode("./builtin_tests/range_check.small.cairo") require.NoError(t, err) - _, _, _, err = runVm(compiledOutput) + _, _, _, _, err = runVm(compiledOutput) require.ErrorContains(t, err, "check write: 2**128 <") clean("./builtin_tests/") @@ -386,7 +389,7 @@ func TestBitwise(t *testing.T) { compiledOutput, err := compileZeroCode("./builtin_tests/bitwise_builtin_test.starknet_with_keccak.cairo") require.NoError(t, err) - _, _, _, err = runVm(compiledOutput) + _, _, _, _, err = runVm(compiledOutput) require.NoError(t, err) clean("./builtin_tests/") @@ -396,7 +399,7 @@ func TestPedersen(t *testing.T) { compiledOutput, err := compileZeroCode("./builtin_tests/pedersen_test.small.cairo") require.NoError(t, err) - _, _, output, err := runVm(compiledOutput) + _, _, _, output, err := runVm(compiledOutput) require.NoError(t, err) require.Contains(t, output, "Program output:\n 2089986280348253421170679821480865132823066470938446095505822317253594081284") @@ -407,7 +410,7 @@ func TestPoseidon(t *testing.T) { compiledOutput, err := compileZeroCode("./builtin_tests/poseidon_test.starknet_with_keccak.cairo") require.NoError(t, err) - _, _, output, err := runVm(compiledOutput) + _, _, _, output, err := runVm(compiledOutput) require.NoError(t, err) require.Contains(t, output, "Program output:\n 442682200349489646213731521593476982257703159825582578145778919623645026501\n 2233832504250924383748553933071188903279928981104663696710686541536735838182\n 2512222140811166287287541003826449032093371832913959128171347018667852712082\n") require.Contains(t, output, "3016509350703874362933565866148509373957094754875411937434637891208784994231\n 3015199725895936530535660185611704199044060139852899280809302949374221328865\n 3062378460350040063467318871602229987911299744598148928378797834245039883769\n") @@ -418,7 +421,7 @@ func TestECDSA(t *testing.T) { compiledOutput, err := compileZeroCode("./builtin_tests/ecdsa_test.starknet_with_keccak.cairo") require.NoError(t, err) - _, _, _, err = runVm(compiledOutput) + _, _, _, _, err = runVm(compiledOutput) require.NoError(t, err) clean("./builtin_tests/") @@ -428,7 +431,7 @@ func TestEcOp(t *testing.T) { compiledOutput, err := compileZeroCode("./builtin_tests/ecop.starknet_with_keccak.cairo") require.NoError(t, err) - _, _, _, err = runVm(compiledOutput) + _, _, _, _, err = runVm(compiledOutput) // todo(rodro): This test is failing due to the lack of hint processing. It should be address soon require.Error(t, err) @@ -439,7 +442,7 @@ func TestKeccak(t *testing.T) { compiledOutput, err := compileZeroCode("./builtin_tests/keccak_test.starknet_with_keccak.cairo") require.NoError(t, err) - _, _, output, err := runVm(compiledOutput) + _, _, _, output, err := runVm(compiledOutput) require.NoError(t, err) require.Contains(t, output, "Program output:\n 1304102964824333531548398680304964155037696012322029952943772\n 688749063493959345342507274897412933692859993314608487848187\n 986714560881445649520443980361539218531403996118322524237197\n 1184757872753521629808292433475729390634371625298664050186717\n 719230200744669084408849842242045083289669818920073250264351\n 1543031433416778513637578850638598357854418012971636697855068\n 63644822371671650271181212513090078620238279557402571802224\n 879446821229338092940381117330194802032344024906379963157761\n") From 9e8db3e990bf69b8c122ae5da0ef30fbbcf18ba0 Mon Sep 17 00:00:00 2001 From: Sh0g0-1758 Date: Fri, 28 Jun 2024 02:20:41 +0530 Subject: [PATCH 3/5] nit --- integration_tests/cairozero_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/integration_tests/cairozero_test.go b/integration_tests/cairozero_test.go index 720939d38..9829da382 100644 --- a/integration_tests/cairozero_test.go +++ b/integration_tests/cairozero_test.go @@ -95,19 +95,19 @@ func TestCairoZeroFiles(t *testing.T) { continue } - elapsed_py, pyTraceFile, pyMemoryFile, err := runPythonVm(dirEntry.Name(), compiledOutput) + elapsedPy, pyTraceFile, pyMemoryFile, err := runPythonVm(dirEntry.Name(), compiledOutput) if err != nil { t.Error(err) continue } - elapsed_go, traceFile, memoryFile, _, err := runVm(compiledOutput) + elapsedGo, traceFile, memoryFile, _, err := runVm(compiledOutput) if err != nil { t.Error(err) continue } - benchmarkMap[dirEntry.Name()] = [2]int{int(elapsed_py.Milliseconds()), int(elapsed_go.Milliseconds())} + benchmarkMap[dirEntry.Name()] = [2]int{int(elapsedPy.Milliseconds()), int(elapsedGo.Milliseconds())} pyTrace, pyMemory, err := decodeProof(pyTraceFile, pyMemoryFile) if err != nil { From cd74a5398c937fb5507990cbda10c01c52b0ef66 Mon Sep 17 00:00:00 2001 From: Sh0g0-1758 Date: Fri, 28 Jun 2024 14:07:43 +0530 Subject: [PATCH 4/5] Minor design changes --- integration_tests/BenchMarks.txt | 95 ++++++++++++++++++++++++----- integration_tests/cairozero_test.go | 12 +++- 2 files changed, 92 insertions(+), 15 deletions(-) diff --git a/integration_tests/BenchMarks.txt b/integration_tests/BenchMarks.txt index 45229d235..a16dae2d4 100644 --- a/integration_tests/BenchMarks.txt +++ b/integration_tests/BenchMarks.txt @@ -1,14 +1,81 @@ -==================================================================== -| File | PythonVM (ms) | GoVM (ms) | -==================================================================== -| fib.cairo | 744 | 130 | -| squash_dict.cairo | 694 | 138 | -| set_add.cairo | 713 | 129 | -| simple.cairo | 729 | 124 | -| test.starknet_with_keccak.cairo | 1682 | 143 | -| alloc.cairo | 716 | 127 | -| dict.cairo | 714 | 123 | -| factorial.cairo | 1312 | 119 | -| find_element.cairo | 668 | 132 | -| hintrefs.cairo | 750 | 144 | -==================================================================== +=========================================================================== +| File | PythonVM (ms) | GoVM (ms) | +=========================================================================== +| sqrt.small.cairo | 1497 | 218 | +--------------------------------------------------------------------------- +| uint256_signedNN.small.cairo | 1163 | 197 | +--------------------------------------------------------------------------- +| uint256_unsigned_div_rem.small.cairo | 1516 | 251 | +--------------------------------------------------------------------------- +| verify_zero.small.cairo | 1287 | 249 | +--------------------------------------------------------------------------- +| alloc.cairo | 1177 | 246 | +--------------------------------------------------------------------------- +| dict.cairo | 1246 | 198 | +--------------------------------------------------------------------------- +| search_sorted_lower.small.cairo | 1246 | 201 | +--------------------------------------------------------------------------- +| is_positive.small.cairo | 1288 | 196 | +--------------------------------------------------------------------------- +| pow.small.cairo | 1411 | 199 | +--------------------------------------------------------------------------- +| unsigned_div_rem.small.cairo | 1445 | 231 | +--------------------------------------------------------------------------- +| assert_250_bits.small.cairo | 1544 | 217 | +--------------------------------------------------------------------------- +| ec.small.cairo | 1754 | 225 | +--------------------------------------------------------------------------- +| split_felt.small.cairo | 1470 | 214 | +--------------------------------------------------------------------------- +| uint256_mul_div_mod.small.cairo | 1645 | 210 | +--------------------------------------------------------------------------- +| usort.small.cairo | 1430 | 228 | +--------------------------------------------------------------------------- +| get_point_from_x.small.cairo | 1622 | 211 | +--------------------------------------------------------------------------- +| import_secp256R1P.small.cairo | 1146 | 199 | +--------------------------------------------------------------------------- +| signed_div_rem.small.cairo | 1174 | 199 | +--------------------------------------------------------------------------- +| uint256_add.small.cairo | 1223 | 249 | +--------------------------------------------------------------------------- +| hintrefs.cairo | 1105 | 195 | +--------------------------------------------------------------------------- +| memset.cairo | 1130 | 197 | +--------------------------------------------------------------------------- +| reduce_v1.small.cairo | 1467 | 219 | +--------------------------------------------------------------------------- +| dict_squash.small.cairo | 1637 | 293 | +--------------------------------------------------------------------------- +| memcpy.cairo | 1212 | 227 | +--------------------------------------------------------------------------- +| set_add.small.cairo | 1034 | 204 | +--------------------------------------------------------------------------- +| split_int.small.cairo | 1255 | 207 | +--------------------------------------------------------------------------- +| uint256_sqrt.small.cairo | 1679 | 223 | +--------------------------------------------------------------------------- +| verify_ecdsa_signature.small.cairo | 1419 | 225 | +--------------------------------------------------------------------------- +| assert_not_zero.cairo | 1116 | 217 | +--------------------------------------------------------------------------- +| blake.starknet_with_keccak.cairo | 4195 | 261 | +--------------------------------------------------------------------------- +| factorial.cairo | 1800 | 204 | +--------------------------------------------------------------------------- +| fib.cairo | 1182 | 235 | +--------------------------------------------------------------------------- +| cmp.small.cairo | 1536 | 210 | +--------------------------------------------------------------------------- +| split64.small.cairo | 1422 | 224 | +--------------------------------------------------------------------------- +| simple.cairo | 1029 | 215 | +--------------------------------------------------------------------------- +| assert_not_equal.cairo | 1030 | 214 | +--------------------------------------------------------------------------- +| is_quad_residue.small.cairo | 1460 | 319 | +--------------------------------------------------------------------------- +| div_mod_n.small.cairo | 1627 | 218 | +--------------------------------------------------------------------------- +| find_element.small.cairo | 1243 | 236 | +=========================================================================== diff --git a/integration_tests/cairozero_test.go b/integration_tests/cairozero_test.go index 9829da382..e264c0d17 100644 --- a/integration_tests/cairozero_test.go +++ b/integration_tests/cairozero_test.go @@ -140,7 +140,7 @@ func TestCairoZeroFiles(t *testing.T) { // Save the Benchmarks for the integration tests in `BenchMarks.txt` func WriteBenchMarksToFile(benchmarkMap map[string][2]int) { headers := []string{"File", "PythonVM (ms)", "GoVM (ms)"} - columnWidths := []int{33, 15, 10} + columnWidths := []int{40, 15, 10} totalWidth := 0 for _, width := range columnWidths { @@ -150,6 +150,7 @@ func WriteBenchMarksToFile(benchmarkMap map[string][2]int) { totalWidth += 1 border := strings.Repeat("=", totalWidth) + separator := strings.Repeat("-", totalWidth) var sb strings.Builder @@ -157,12 +158,21 @@ func WriteBenchMarksToFile(benchmarkMap map[string][2]int) { sb.WriteString(formatRow(headers, columnWidths) + "\n") sb.WriteString(border + "\n") + iterator := 0 + totalFiles := len(benchmarkMap) + for key, values := range benchmarkMap { row := []string{key} for _, value := range values { row = append(row, strconv.Itoa(value)) } sb.WriteString(formatRow(row, columnWidths) + "\n") + + if iterator < totalFiles-1 { + sb.WriteString(separator + "\n") + } + + iterator++ } sb.WriteString(border + "\n") From 46f20e778637a052fce06236d61519bc2e8682d5 Mon Sep 17 00:00:00 2001 From: Sh0g0-1758 Date: Fri, 28 Jun 2024 17:13:58 +0530 Subject: [PATCH 5/5] Using tabwriter --- integration_tests/BenchMarks.txt | 162 ++++++++++++++-------------- integration_tests/cairozero_test.go | 44 +++----- 2 files changed, 96 insertions(+), 110 deletions(-) diff --git a/integration_tests/BenchMarks.txt b/integration_tests/BenchMarks.txt index a16dae2d4..460afc40e 100644 --- a/integration_tests/BenchMarks.txt +++ b/integration_tests/BenchMarks.txt @@ -1,81 +1,81 @@ -=========================================================================== -| File | PythonVM (ms) | GoVM (ms) | -=========================================================================== -| sqrt.small.cairo | 1497 | 218 | ---------------------------------------------------------------------------- -| uint256_signedNN.small.cairo | 1163 | 197 | ---------------------------------------------------------------------------- -| uint256_unsigned_div_rem.small.cairo | 1516 | 251 | ---------------------------------------------------------------------------- -| verify_zero.small.cairo | 1287 | 249 | ---------------------------------------------------------------------------- -| alloc.cairo | 1177 | 246 | ---------------------------------------------------------------------------- -| dict.cairo | 1246 | 198 | ---------------------------------------------------------------------------- -| search_sorted_lower.small.cairo | 1246 | 201 | ---------------------------------------------------------------------------- -| is_positive.small.cairo | 1288 | 196 | ---------------------------------------------------------------------------- -| pow.small.cairo | 1411 | 199 | ---------------------------------------------------------------------------- -| unsigned_div_rem.small.cairo | 1445 | 231 | ---------------------------------------------------------------------------- -| assert_250_bits.small.cairo | 1544 | 217 | ---------------------------------------------------------------------------- -| ec.small.cairo | 1754 | 225 | ---------------------------------------------------------------------------- -| split_felt.small.cairo | 1470 | 214 | ---------------------------------------------------------------------------- -| uint256_mul_div_mod.small.cairo | 1645 | 210 | ---------------------------------------------------------------------------- -| usort.small.cairo | 1430 | 228 | ---------------------------------------------------------------------------- -| get_point_from_x.small.cairo | 1622 | 211 | ---------------------------------------------------------------------------- -| import_secp256R1P.small.cairo | 1146 | 199 | ---------------------------------------------------------------------------- -| signed_div_rem.small.cairo | 1174 | 199 | ---------------------------------------------------------------------------- -| uint256_add.small.cairo | 1223 | 249 | ---------------------------------------------------------------------------- -| hintrefs.cairo | 1105 | 195 | ---------------------------------------------------------------------------- -| memset.cairo | 1130 | 197 | ---------------------------------------------------------------------------- -| reduce_v1.small.cairo | 1467 | 219 | ---------------------------------------------------------------------------- -| dict_squash.small.cairo | 1637 | 293 | ---------------------------------------------------------------------------- -| memcpy.cairo | 1212 | 227 | ---------------------------------------------------------------------------- -| set_add.small.cairo | 1034 | 204 | ---------------------------------------------------------------------------- -| split_int.small.cairo | 1255 | 207 | ---------------------------------------------------------------------------- -| uint256_sqrt.small.cairo | 1679 | 223 | ---------------------------------------------------------------------------- -| verify_ecdsa_signature.small.cairo | 1419 | 225 | ---------------------------------------------------------------------------- -| assert_not_zero.cairo | 1116 | 217 | ---------------------------------------------------------------------------- -| blake.starknet_with_keccak.cairo | 4195 | 261 | ---------------------------------------------------------------------------- -| factorial.cairo | 1800 | 204 | ---------------------------------------------------------------------------- -| fib.cairo | 1182 | 235 | ---------------------------------------------------------------------------- -| cmp.small.cairo | 1536 | 210 | ---------------------------------------------------------------------------- -| split64.small.cairo | 1422 | 224 | ---------------------------------------------------------------------------- -| simple.cairo | 1029 | 215 | ---------------------------------------------------------------------------- -| assert_not_equal.cairo | 1030 | 214 | ---------------------------------------------------------------------------- -| is_quad_residue.small.cairo | 1460 | 319 | ---------------------------------------------------------------------------- -| div_mod_n.small.cairo | 1627 | 218 | ---------------------------------------------------------------------------- -| find_element.small.cairo | 1243 | 236 | -=========================================================================== +=========================================================================================================================== +| File | PythonVM (ms) | GoVM (ms) | +=========================================================================================================================== +| get_point_from_x.small.cairo | 971 | 125 | +--------------------------------------------------------------------------------------------------------------------------- +| is_quad_residue.small.cairo | 963 | 152 | +--------------------------------------------------------------------------------------------------------------------------- +| reduce_v1.small.cairo | 931 | 130 | +--------------------------------------------------------------------------------------------------------------------------- +| uint256_unsigned_div_rem.small.cairo | 1061 | 132 | +--------------------------------------------------------------------------------------------------------------------------- +| set_add.small.cairo | 749 | 117 | +--------------------------------------------------------------------------------------------------------------------------- +| split64.small.cairo | 1014 | 117 | +--------------------------------------------------------------------------------------------------------------------------- +| uint256_signedNN.small.cairo | 752 | 114 | +--------------------------------------------------------------------------------------------------------------------------- +| split_felt.small.cairo | 841 | 145 | +--------------------------------------------------------------------------------------------------------------------------- +| split_int.small.cairo | 1037 | 133 | +--------------------------------------------------------------------------------------------------------------------------- +| uint256_add.small.cairo | 921 | 110 | +--------------------------------------------------------------------------------------------------------------------------- +| signed_div_rem.small.cairo | 816 | 117 | +--------------------------------------------------------------------------------------------------------------------------- +| sqrt.small.cairo | 960 | 119 | +--------------------------------------------------------------------------------------------------------------------------- +| uint256_sqrt.small.cairo | 1195 | 115 | +--------------------------------------------------------------------------------------------------------------------------- +| assert_not_zero.cairo | 586 | 100 | +--------------------------------------------------------------------------------------------------------------------------- +| blake.starknet_with_keccak.cairo | 2498 | 144 | +--------------------------------------------------------------------------------------------------------------------------- +| import_secp256R1P.small.cairo | 699 | 123 | +--------------------------------------------------------------------------------------------------------------------------- +| memcpy.cairo | 704 | 124 | +--------------------------------------------------------------------------------------------------------------------------- +| unsigned_div_rem.small.cairo | 843 | 118 | +--------------------------------------------------------------------------------------------------------------------------- +| factorial.cairo | 1161 | 123 | +--------------------------------------------------------------------------------------------------------------------------- +| hintrefs.cairo | 676 | 127 | +--------------------------------------------------------------------------------------------------------------------------- +| cmp.small.cairo | 897 | 110 | +--------------------------------------------------------------------------------------------------------------------------- +| dict_squash.small.cairo | 1240 | 166 | +--------------------------------------------------------------------------------------------------------------------------- +| div_mod_n.small.cairo | 921 | 113 | +--------------------------------------------------------------------------------------------------------------------------- +| find_element.small.cairo | 939 | 124 | +--------------------------------------------------------------------------------------------------------------------------- +| uint256_mul_div_mod.small.cairo | 1032 | 119 | +--------------------------------------------------------------------------------------------------------------------------- +| verify_zero.small.cairo | 781 | 112 | +--------------------------------------------------------------------------------------------------------------------------- +| ec.small.cairo | 1042 | 129 | +--------------------------------------------------------------------------------------------------------------------------- +| memset.cairo | 701 | 128 | +--------------------------------------------------------------------------------------------------------------------------- +| pow.small.cairo | 887 | 112 | +--------------------------------------------------------------------------------------------------------------------------- +| search_sorted_lower.small.cairo | 836 | 134 | +--------------------------------------------------------------------------------------------------------------------------- +| alloc.cairo | 666 | 126 | +--------------------------------------------------------------------------------------------------------------------------- +| simple.cairo | 596 | 110 | +--------------------------------------------------------------------------------------------------------------------------- +| assert_250_bits.small.cairo | 979 | 120 | +--------------------------------------------------------------------------------------------------------------------------- +| assert_not_equal.cairo | 638 | 101 | +--------------------------------------------------------------------------------------------------------------------------- +| dict.cairo | 678 | 115 | +--------------------------------------------------------------------------------------------------------------------------- +| is_positive.small.cairo | 884 | 128 | +--------------------------------------------------------------------------------------------------------------------------- +| usort.small.cairo | 797 | 119 | +--------------------------------------------------------------------------------------------------------------------------- +| verify_ecdsa_signature.small.cairo | 758 | 117 | +--------------------------------------------------------------------------------------------------------------------------- +| fib.cairo | 634 | 116 | +=========================================================================================================================== diff --git a/integration_tests/cairozero_test.go b/integration_tests/cairozero_test.go index e264c0d17..04653c83d 100644 --- a/integration_tests/cairozero_test.go +++ b/integration_tests/cairozero_test.go @@ -8,6 +8,7 @@ import ( "strconv" "strings" "testing" + "text/tabwriter" "time" "github.com/NethermindEth/cairo-vm-go/pkg/vm" @@ -139,34 +140,34 @@ func TestCairoZeroFiles(t *testing.T) { // Save the Benchmarks for the integration tests in `BenchMarks.txt` func WriteBenchMarksToFile(benchmarkMap map[string][2]int) { - headers := []string{"File", "PythonVM (ms)", "GoVM (ms)"} - columnWidths := []int{40, 15, 10} - - totalWidth := 0 - for _, width := range columnWidths { - totalWidth += width + 3 - } - - totalWidth += 1 + totalWidth := 123 border := strings.Repeat("=", totalWidth) separator := strings.Repeat("-", totalWidth) var sb strings.Builder + w := tabwriter.NewWriter(&sb, 40, 0, 0, ' ', tabwriter.Debug) sb.WriteString(border + "\n") - sb.WriteString(formatRow(headers, columnWidths) + "\n") + fmt.Fprintln(w, "| File \t PythonVM (ms) \t GoVM (ms) \t") + w.Flush() sb.WriteString(border + "\n") iterator := 0 totalFiles := len(benchmarkMap) for key, values := range benchmarkMap { - row := []string{key} - for _, value := range values { - row = append(row, strconv.Itoa(value)) + row := "| " + key + "\t " + + for iter, value := range values { + row = row + strconv.Itoa(value) + "\t" + if iter == 0 { + row = row + " " + } } - sb.WriteString(formatRow(row, columnWidths) + "\n") + + fmt.Fprintln(w, row) + w.Flush() if iterator < totalFiles-1 { sb.WriteString(separator + "\n") @@ -193,21 +194,6 @@ func WriteBenchMarksToFile(benchmarkMap map[string][2]int) { } } -// format a row with borders and spaces based on the column widths -func formatRow(row []string, widths []int) string { - var sb strings.Builder - sb.WriteString("|") - for i, col := range row { - sb.WriteString(" " + padRight(col, widths[i]) + " |") - } - return sb.String() -} - -// pad a string with spaces to the right to match the given width -func padRight(str string, width int) string { - return fmt.Sprintf("%-"+fmt.Sprintf("%d", width)+"s", str) -} - const ( compiledSuffix = "_compiled.json" pyTraceSuffix = "_py_trace"