Skip to content

Commit

Permalink
Using tabwriter
Browse files Browse the repository at this point in the history
  • Loading branch information
Sh0g0-1758 committed Jun 28, 2024
1 parent cd74a53 commit 46f20e7
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 110 deletions.
162 changes: 81 additions & 81 deletions integration_tests/BenchMarks.txt
Original file line number Diff line number Diff line change
@@ -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 |
===========================================================================================================================
44 changes: 15 additions & 29 deletions integration_tests/cairozero_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strconv"
"strings"
"testing"
"text/tabwriter"
"time"

"github.com/NethermindEth/cairo-vm-go/pkg/vm"
Expand Down Expand Up @@ -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")
Expand All @@ -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"
Expand Down

0 comments on commit 46f20e7

Please sign in to comment.