From c04e65463ad830fb55fad37d14762744045894ab Mon Sep 17 00:00:00 2001 From: Bryan Huhta Date: Tue, 7 Nov 2023 07:55:19 -0600 Subject: [PATCH 1/3] Add support for -benchmem format --- bench2csv.go | 33 ++++++++- bench2csv_test.go | 12 ++++ cmd/bench2csv/main.go | 5 ++ testdata/input2.txt | 159 ++++++++++++++++++++++++++++++++++++++++++ testdata/output3.csv | 155 ++++++++++++++++++++++++++++++++++++++++ testdata/output4.csv | 155 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 517 insertions(+), 2 deletions(-) create mode 100644 testdata/input2.txt create mode 100644 testdata/output3.csv create mode 100644 testdata/output4.csv diff --git a/bench2csv.go b/bench2csv.go index 8088c1a..5cf54a1 100644 --- a/bench2csv.go +++ b/bench2csv.go @@ -15,10 +15,13 @@ const ( Operations Duration Frequency + BytesPerOp + AllocsPerOp Default = Name | Parallelism | Operations | Duration + Mem = BytesPerOp | AllocsPerOp ) -// benchmakrMatcher matches a benchmark output line. +// benchmarkMatcher matches a benchmark output line. // See https://regex101.com/r/Uv4LNN/latest var benchmarkMatcher = regexp.MustCompile( `^Benchmark` + // "Benchmark" prefix @@ -29,7 +32,14 @@ var benchmarkMatcher = regexp.MustCompile( `\s+` + `(?P\d+(?:\.\d+)?)` + // Duration for each operation `\sns/op` + // Duration unit suffix - `$`) + + // Optionally, with -benchmem... + `(\s+` + + `(?P\d+)` + // Bytes per operation + `\sB/op\s+` + // Bytes per operation unit suffix + `(?P\d+)` + // Allocs per operation + `\sallocs/op` + // Allocs per operation unit suffix + `)?$`) // Process benchmark output from in, write CSV to csvOut, and pipe benchmark output to errOut. func Process(in io.Reader, csvOut, errOut io.Writer, format int) error { @@ -51,6 +61,12 @@ func Process(in io.Reader, csvOut, errOut io.Writer, format int) error { if format&Frequency != 0 { header = append(header, "frequency") } + if format&BytesPerOp != 0 { + header = append(header, "bytes_per_op") + } + if format&AllocsPerOp != 0 { + header = append(header, "allocs_per_op") + } if _, err := fmt.Fprintln(csvOut, strings.Join(header, ",")); err != nil { return err @@ -74,6 +90,13 @@ func Process(in io.Reader, csvOut, errOut io.Writer, format int) error { operations := submatches[2] duration := submatches[3] + bytesPerOp := "0" + allocsPerOp := "0" + if len(submatches) > 6 { + bytesPerOp = submatches[5] + allocsPerOp = submatches[6] + } + if parallelism == "" { parallelism = "1" } @@ -100,6 +123,12 @@ func Process(in io.Reader, csvOut, errOut io.Writer, format int) error { if format&Frequency != 0 { values = append(values, frequency) } + if format&BytesPerOp != 0 { + values = append(values, bytesPerOp) + } + if format&AllocsPerOp != 0 { + values = append(values, allocsPerOp) + } if _, err := fmt.Fprintln(csvOut, strings.Join(values, ",")); err != nil { return err diff --git a/bench2csv_test.go b/bench2csv_test.go index b31bd6b..ee048df 100644 --- a/bench2csv_test.go +++ b/bench2csv_test.go @@ -36,6 +36,18 @@ func TestProcess(t *testing.T) { } }) + t.Run("outputs CSV with benchmem statistics if set", func(t *testing.T) { + var csv strings.Builder + + err := bench2csv.Process(strings.NewReader(readFile(t, "input2.txt")), &csv, io.Discard, + bench2csv.Default|bench2csv.Mem) + noErr(t, err) + + if csv.String() != readFile(t, "output3.csv") { + t.Fatal("Unexpected output:", csv.String()) + } + }) + t.Run("pipes input to output", func(t *testing.T) { input := readFile(t, "input1.txt") diff --git a/cmd/bench2csv/main.go b/cmd/bench2csv/main.go index 3039db7..4542302 100644 --- a/cmd/bench2csv/main.go +++ b/cmd/bench2csv/main.go @@ -19,6 +19,7 @@ func start() error { format := bench2csv.Default freq := flag.Bool("freq", false, "Include frequency output") + mem := flag.Bool("mem", false, "Include -benchmem statistics output") flag.Parse() @@ -26,5 +27,9 @@ func start() error { format |= bench2csv.Frequency } + if *mem { + format |= bench2csv.Mem + } + return bench2csv.Process(os.Stdin, os.Stdout, os.Stderr, format) } diff --git a/testdata/input2.txt b/testdata/input2.txt new file mode 100644 index 0000000..479ba17 --- /dev/null +++ b/testdata/input2.txt @@ -0,0 +1,159 @@ +goos: darwin +goarch: arm64 +pkg: github.com/maragudk/sqlite-benchmark +BenchmarkSelect1 790153 1495 ns/op 168 B/op 12 allocs/op +BenchmarkSelect1-2 1345888 926.5 ns/op 168 B/op 12 allocs/op +BenchmarkSelect1-4 1029002 1028 ns/op 188 B/op 12 allocs/op +BenchmarkSelect1-8 869827 1360 ns/op 185 B/op 12 allocs/op +BenchmarkSelect1-16 545296 1952 ns/op 189 B/op 12 allocs/op +BenchmarkSelect1-32 547129 2153 ns/op 193 B/op 12 allocs/op +BenchmarkSelect1-64 518738 2284 ns/op 195 B/op 12 allocs/op +BenchmarkSelect1-128 418438 2505 ns/op 196 B/op 12 allocs/op +BenchmarkSelect1-256 412849 2716 ns/op 198 B/op 13 allocs/op +BenchmarkSelect1-512 367188 2967 ns/op 201 B/op 13 allocs/op +BenchmarkSelect1-1024 323995 3346 ns/op 204 B/op 13 allocs/op +BenchmarkDB_ReadPost/mutex_false 106851 10855 ns/op 5064 B/op 70 allocs/op +BenchmarkDB_ReadPost/mutex_false-2 184839 6378 ns/op 5064 B/op 70 allocs/op +BenchmarkDB_ReadPost/mutex_false-4 255727 4621 ns/op 5072 B/op 70 allocs/op +BenchmarkDB_ReadPost/mutex_false-8 186601 6734 ns/op 5117 B/op 71 allocs/op +BenchmarkDB_ReadPost/mutex_false-16 118801 9543 ns/op 5143 B/op 72 allocs/op +BenchmarkDB_ReadPost/mutex_false-32 126266 10449 ns/op 5153 B/op 73 allocs/op +BenchmarkDB_ReadPost/mutex_false-64 87142 12151 ns/op 5173 B/op 73 allocs/op +BenchmarkDB_ReadPost/mutex_false-128 75932 14635 ns/op 5188 B/op 74 allocs/op +BenchmarkDB_ReadPost/mutex_false-256 71932 15458 ns/op 5222 B/op 74 allocs/op +BenchmarkDB_ReadPost/mutex_false-512 71619 19066 ns/op 5277 B/op 75 allocs/op +BenchmarkDB_ReadPost/mutex_false-1024 64186 17347 ns/op 5270 B/op 75 allocs/op +BenchmarkDB_ReadPost/mutex_true 103255 10907 ns/op 5064 B/op 70 allocs/op +BenchmarkDB_ReadPost/mutex_true-2 185330 6205 ns/op 5064 B/op 70 allocs/op +BenchmarkDB_ReadPost/mutex_true-4 260004 4542 ns/op 5074 B/op 70 allocs/op +BenchmarkDB_ReadPost/mutex_true-8 176294 6872 ns/op 5121 B/op 71 allocs/op +BenchmarkDB_ReadPost/mutex_true-16 110013 9815 ns/op 5142 B/op 72 allocs/op +BenchmarkDB_ReadPost/mutex_true-32 108694 10602 ns/op 5152 B/op 73 allocs/op +BenchmarkDB_ReadPost/mutex_true-64 83280 13206 ns/op 5179 B/op 73 allocs/op +BenchmarkDB_ReadPost/mutex_true-128 87104 13786 ns/op 5192 B/op 74 allocs/op +BenchmarkDB_ReadPost/mutex_true-256 78757 17134 ns/op 5238 B/op 75 allocs/op +BenchmarkDB_ReadPost/mutex_true-512 71954 16031 ns/op 5235 B/op 74 allocs/op +BenchmarkDB_ReadPost/mutex_true-1024 67196 16484 ns/op 5259 B/op 75 allocs/op +BenchmarkDB_WritePost/mutex_false 36357 30772 ns/op 3992 B/op 22 allocs/op +BenchmarkDB_WritePost/mutex_false-2 37180 29474 ns/op 3992 B/op 22 allocs/op +BenchmarkDB_WritePost/mutex_false-4 32991 30380 ns/op 3992 B/op 22 allocs/op +BenchmarkDB_WritePost/mutex_false-8 36916 28763 ns/op 3992 B/op 22 allocs/op +BenchmarkDB_WritePost/mutex_false-16 36807 32934 ns/op 3992 B/op 22 allocs/op +BenchmarkDB_WritePost/mutex_false-32 33592 36169 ns/op 3993 B/op 22 allocs/op +BenchmarkDB_WritePost/mutex_false-64 30153 39105 ns/op 3996 B/op 22 allocs/op +BenchmarkDB_WritePost/mutex_false-128 9181 139202 ns/op 4017 B/op 22 allocs/op +BenchmarkDB_WritePost/mutex_false-256 1071 1013229 ns/op 4410 B/op 35 allocs/op +BenchmarkDB_WritePost/mutex_false-512 1748 585838 ns/op 4587 B/op 38 allocs/op +BenchmarkDB_WritePost/mutex_false-1024 1171 880128 ns/op 5790 B/op 66 allocs/op +BenchmarkDB_WritePost/mutex_true 37920 30144 ns/op 3992 B/op 22 allocs/op +BenchmarkDB_WritePost/mutex_true-2 38636 30683 ns/op 3992 B/op 22 allocs/op +BenchmarkDB_WritePost/mutex_true-4 28395 40384 ns/op 3992 B/op 22 allocs/op +BenchmarkDB_WritePost/mutex_true-8 28808 40272 ns/op 3993 B/op 22 allocs/op +BenchmarkDB_WritePost/mutex_true-16 29643 40757 ns/op 3994 B/op 22 allocs/op +BenchmarkDB_WritePost/mutex_true-32 30112 38741 ns/op 3993 B/op 22 allocs/op +BenchmarkDB_WritePost/mutex_true-64 29664 38403 ns/op 3993 B/op 22 allocs/op +BenchmarkDB_WritePost/mutex_true-128 30157 39709 ns/op 3993 B/op 22 allocs/op +BenchmarkDB_WritePost/mutex_true-256 23594 48219 ns/op 3994 B/op 22 allocs/op +BenchmarkDB_WritePost/mutex_true-512 25057 48119 ns/op 3996 B/op 22 allocs/op +BenchmarkDB_WritePost/mutex_true-1024 34506 33607 ns/op 3998 B/op 22 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01 19478 111816 ns/op 26677 B/op 1617 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01-2 37039 103416 ns/op 43744 B/op 2845 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01-4 65499 86358 ns/op 67702 B/op 4623 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01-8 80562 84669 ns/op 86565 B/op 6039 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01-16 68466 72408 ns/op 79267 B/op 5471 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01-32 71906 72345 ns/op 79347 B/op 5496 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01-64 59551 57229 ns/op 60165 B/op 4096 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01-128 59228 63038 ns/op 63485 B/op 4319 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01-256 53848 67016 ns/op 65556 B/op 4480 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01-512 45206 52034 ns/op 50496 B/op 3357 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01-1024 35100 48329 ns/op 40763 B/op 2603 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1 10000 489216 ns/op 113297 B/op 7985 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1-2 10000 253993 ns/op 111447 B/op 7858 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1-4 10000 147819 ns/op 113389 B/op 7994 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1-8 17343 182012 ns/op 187002 B/op 13390 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1-16 12104 128664 ns/op 135394 B/op 9635 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1-32 10000 102599 ns/op 105050 B/op 7388 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1-64 10000 104560 ns/op 108341 B/op 7618 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1-128 10000 101213 ns/op 100018 B/op 7009 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1-256 10000 105364 ns/op 102519 B/op 7188 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1-512 10000 121744 ns/op 102152 B/op 7158 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1-1024 10000 117114 ns/op 101494 B/op 7109 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1 10000 4675206 ns/op 1119965 B/op 79760 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1-2 10000 2582670 ns/op 1119739 B/op 79744 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1-4 5805 856084 ns/op 646712 B/op 46154 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1-8 5210 580638 ns/op 577437 B/op 41331 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1-16 4800 516089 ns/op 530896 B/op 37926 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1-32 4851 498834 ns/op 533080 B/op 38087 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1-64 4603 501852 ns/op 499405 B/op 35614 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1-128 3414 402022 ns/op 351933 B/op 25193 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1-256 2062 587665 ns/op 177435 B/op 12654 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1-512 1000 1131322 ns/op 47263 B/op 3037 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1-1024 1813 744656 ns/op 102558 B/op 7065 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01 17838 104167 ns/op 24994 B/op 1494 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01-2 38834 109734 ns/op 48091 B/op 3175 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01-4 66880 103785 ns/op 78966 B/op 5464 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01-8 44755 54003 ns/op 48802 B/op 3227 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01-16 34405 49750 ns/op 36652 B/op 2320 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01-32 25586 62076 ns/op 31154 B/op 1934 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01-64 22818 64795 ns/op 28769 B/op 1760 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01-128 26546 62908 ns/op 27604 B/op 1672 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01-256 30226 48744 ns/op 21346 B/op 1212 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01-512 31393 40450 ns/op 12903 B/op 615 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01-1024 24115 51386 ns/op 8247 B/op 281 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1 10000 490641 ns/op 110553 B/op 7783 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1-2 10000 249135 ns/op 103567 B/op 7278 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1-4 10000 178316 ns/op 112517 B/op 7920 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1-8 10000 177056 ns/op 116813 B/op 8221 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1-16 10000 212731 ns/op 108290 B/op 7569 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1-32 10000 217131 ns/op 111280 B/op 7794 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1-64 10000 206609 ns/op 102449 B/op 7150 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1-128 10000 190087 ns/op 91471 B/op 6356 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1-256 10000 167718 ns/op 66593 B/op 4520 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1-512 10000 122500 ns/op 35825 B/op 2270 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1-1024 24273 218542 ns/op 104321 B/op 7244 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1 10000 4740601 ns/op 1119965 B/op 79760 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1-2 10000 4461101 ns/op 1119738 B/op 79744 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1-4 10000 4482083 ns/op 1119284 B/op 79712 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1-8 10000 4471042 ns/op 1118377 B/op 79648 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1-16 9495 4244922 ns/op 1057632 B/op 75497 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1-32 8308 3706785 ns/op 920787 B/op 65747 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1-64 3537 1581670 ns/op 378268 B/op 27084 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1-128 10000 4461710 ns/op 1091493 B/op 77762 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1-256 4496 1858876 ns/op 446386 B/op 31788 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1-512 6118 2408634 ns/op 573481 B/op 40917 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1-1024 9177 3422506 ns/op 809698 B/op 57778 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01 21085 117309 ns/op 27685 B/op 1685 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01-2 43975 101870 ns/op 45042 B/op 2942 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01-4 78451 111886 ns/op 87857 B/op 6133 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01-8 76304 76784 ns/op 78314 B/op 5418 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01-16 69585 86344 ns/op 81991 B/op 5685 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01-32 63589 77846 ns/op 72992 B/op 5016 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01-64 55986 67619 ns/op 63156 B/op 4293 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01-128 53895 69871 ns/op 60694 B/op 4133 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01-256 46215 59630 ns/op 49458 B/op 3287 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01-512 43458 56761 ns/op 50406 B/op 3341 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01-1024 28617 46028 ns/op 34658 B/op 2168 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1 10000 522792 ns/op 118176 B/op 8352 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1-2 10000 247172 ns/op 102583 B/op 7218 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1-4 10000 148170 ns/op 112700 B/op 7951 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1-8 10000 105121 ns/op 105284 B/op 7408 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1-16 10000 108965 ns/op 114157 B/op 8048 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1-32 10000 105095 ns/op 107728 B/op 7585 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1-64 10000 100849 ns/op 101855 B/op 7133 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1-128 12560 129951 ns/op 124671 B/op 8851 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1-256 15062 133866 ns/op 125743 B/op 8861 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1-512 19910 150991 ns/op 143425 B/op 10208 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1-1024 17707 88389 ns/op 67253 B/op 4569 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1 10000 4974384 ns/op 1119966 B/op 79760 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1-2 9831 2797821 ns/op 1100069 B/op 78392 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1-4 10000 1585898 ns/op 1119320 B/op 79713 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1-8 10000 1158135 ns/op 1118490 B/op 79652 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1-16 9338 1054451 ns/op 1039173 B/op 74240 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1-32 10000 1140638 ns/op 1113942 B/op 79305 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1-64 10000 1181683 ns/op 1107369 B/op 78835 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1-128 10000 1255394 ns/op 1093841 B/op 77846 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1-256 8662 1023898 ns/op 916324 B/op 65390 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1-512 10000 1116866 ns/op 1017457 B/op 72413 allocs/op +BenchmarkDB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1-1024 8236 815912 ns/op 736624 B/op 52294 allocs/op +PASS +ok github.com/maragudk/sqlite-benchmark 937.946s diff --git a/testdata/output3.csv b/testdata/output3.csv new file mode 100644 index 0000000..c2a4d9c --- /dev/null +++ b/testdata/output3.csv @@ -0,0 +1,155 @@ +name,parallelism,operations,duration,bytes_per_op,allocs_per_op +Select1,1,790153,1495,168,12 +Select1,2,1345888,926.5,168,12 +Select1,4,1029002,1028,188,12 +Select1,8,869827,1360,185,12 +Select1,16,545296,1952,189,12 +Select1,32,547129,2153,193,12 +Select1,64,518738,2284,195,12 +Select1,128,418438,2505,196,12 +Select1,256,412849,2716,198,13 +Select1,512,367188,2967,201,13 +Select1,1024,323995,3346,204,13 +DB_ReadPost/mutex_false,1,106851,10855,5064,70 +DB_ReadPost/mutex_false,2,184839,6378,5064,70 +DB_ReadPost/mutex_false,4,255727,4621,5072,70 +DB_ReadPost/mutex_false,8,186601,6734,5117,71 +DB_ReadPost/mutex_false,16,118801,9543,5143,72 +DB_ReadPost/mutex_false,32,126266,10449,5153,73 +DB_ReadPost/mutex_false,64,87142,12151,5173,73 +DB_ReadPost/mutex_false,128,75932,14635,5188,74 +DB_ReadPost/mutex_false,256,71932,15458,5222,74 +DB_ReadPost/mutex_false,512,71619,19066,5277,75 +DB_ReadPost/mutex_false,1024,64186,17347,5270,75 +DB_ReadPost/mutex_true,1,103255,10907,5064,70 +DB_ReadPost/mutex_true,2,185330,6205,5064,70 +DB_ReadPost/mutex_true,4,260004,4542,5074,70 +DB_ReadPost/mutex_true,8,176294,6872,5121,71 +DB_ReadPost/mutex_true,16,110013,9815,5142,72 +DB_ReadPost/mutex_true,32,108694,10602,5152,73 +DB_ReadPost/mutex_true,64,83280,13206,5179,73 +DB_ReadPost/mutex_true,128,87104,13786,5192,74 +DB_ReadPost/mutex_true,256,78757,17134,5238,75 +DB_ReadPost/mutex_true,512,71954,16031,5235,74 +DB_ReadPost/mutex_true,1024,67196,16484,5259,75 +DB_WritePost/mutex_false,1,36357,30772,3992,22 +DB_WritePost/mutex_false,2,37180,29474,3992,22 +DB_WritePost/mutex_false,4,32991,30380,3992,22 +DB_WritePost/mutex_false,8,36916,28763,3992,22 +DB_WritePost/mutex_false,16,36807,32934,3992,22 +DB_WritePost/mutex_false,32,33592,36169,3993,22 +DB_WritePost/mutex_false,64,30153,39105,3996,22 +DB_WritePost/mutex_false,128,9181,139202,4017,22 +DB_WritePost/mutex_false,256,1071,1013229,4410,35 +DB_WritePost/mutex_false,512,1748,585838,4587,38 +DB_WritePost/mutex_false,1024,1171,880128,5790,66 +DB_WritePost/mutex_true,1,37920,30144,3992,22 +DB_WritePost/mutex_true,2,38636,30683,3992,22 +DB_WritePost/mutex_true,4,28395,40384,3992,22 +DB_WritePost/mutex_true,8,28808,40272,3993,22 +DB_WritePost/mutex_true,16,29643,40757,3994,22 +DB_WritePost/mutex_true,32,30112,38741,3993,22 +DB_WritePost/mutex_true,64,29664,38403,3993,22 +DB_WritePost/mutex_true,128,30157,39709,3993,22 +DB_WritePost/mutex_true,256,23594,48219,3994,22 +DB_WritePost/mutex_true,512,25057,48119,3996,22 +DB_WritePost/mutex_true,1024,34506,33607,3998,22 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01,1,19478,111816,26677,1617 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01,2,37039,103416,43744,2845 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01,4,65499,86358,67702,4623 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01,8,80562,84669,86565,6039 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01,16,68466,72408,79267,5471 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01,32,71906,72345,79347,5496 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01,64,59551,57229,60165,4096 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01,128,59228,63038,63485,4319 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01,256,53848,67016,65556,4480 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01,512,45206,52034,50496,3357 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01,1024,35100,48329,40763,2603 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1,1,10000,489216,113297,7985 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1,2,10000,253993,111447,7858 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1,4,10000,147819,113389,7994 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1,8,17343,182012,187002,13390 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1,16,12104,128664,135394,9635 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1,32,10000,102599,105050,7388 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1,64,10000,104560,108341,7618 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1,128,10000,101213,100018,7009 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1,256,10000,105364,102519,7188 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1,512,10000,121744,102152,7158 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1,1024,10000,117114,101494,7109 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1,1,10000,4675206,1119965,79760 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1,2,10000,2582670,1119739,79744 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1,4,5805,856084,646712,46154 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1,8,5210,580638,577437,41331 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1,16,4800,516089,530896,37926 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1,32,4851,498834,533080,38087 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1,64,4603,501852,499405,35614 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1,128,3414,402022,351933,25193 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1,256,2062,587665,177435,12654 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1,512,1000,1131322,47263,3037 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1,1024,1813,744656,102558,7065 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01,1,17838,104167,24994,1494 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01,2,38834,109734,48091,3175 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01,4,66880,103785,78966,5464 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01,8,44755,54003,48802,3227 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01,16,34405,49750,36652,2320 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01,32,25586,62076,31154,1934 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01,64,22818,64795,28769,1760 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01,128,26546,62908,27604,1672 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01,256,30226,48744,21346,1212 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01,512,31393,40450,12903,615 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01,1024,24115,51386,8247,281 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1,1,10000,490641,110553,7783 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1,2,10000,249135,103567,7278 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1,4,10000,178316,112517,7920 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1,8,10000,177056,116813,8221 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1,16,10000,212731,108290,7569 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1,32,10000,217131,111280,7794 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1,64,10000,206609,102449,7150 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1,128,10000,190087,91471,6356 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1,256,10000,167718,66593,4520 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1,512,10000,122500,35825,2270 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1,1024,24273,218542,104321,7244 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1,1,10000,4740601,1119965,79760 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1,2,10000,4461101,1119738,79744 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1,4,10000,4482083,1119284,79712 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1,8,10000,4471042,1118377,79648 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1,16,9495,4244922,1057632,75497 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1,32,8308,3706785,920787,65747 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1,64,3537,1581670,378268,27084 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1,128,10000,4461710,1091493,77762 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1,256,4496,1858876,446386,31788 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1,512,6118,2408634,573481,40917 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1,1024,9177,3422506,809698,57778 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01,1,21085,117309,27685,1685 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01,2,43975,101870,45042,2942 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01,4,78451,111886,87857,6133 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01,8,76304,76784,78314,5418 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01,16,69585,86344,81991,5685 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01,32,63589,77846,72992,5016 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01,64,55986,67619,63156,4293 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01,128,53895,69871,60694,4133 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01,256,46215,59630,49458,3287 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01,512,43458,56761,50406,3341 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01,1024,28617,46028,34658,2168 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1,1,10000,522792,118176,8352 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1,2,10000,247172,102583,7218 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1,4,10000,148170,112700,7951 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1,8,10000,105121,105284,7408 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1,16,10000,108965,114157,8048 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1,32,10000,105095,107728,7585 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1,64,10000,100849,101855,7133 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1,128,12560,129951,124671,8851 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1,256,15062,133866,125743,8861 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1,512,19910,150991,143425,10208 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1,1024,17707,88389,67253,4569 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1,1,10000,4974384,1119966,79760 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1,2,9831,2797821,1100069,78392 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1,4,10000,1585898,1119320,79713 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1,8,10000,1158135,1118490,79652 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1,16,9338,1054451,1039173,74240 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1,32,10000,1140638,1113942,79305 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1,64,10000,1181683,1107369,78835 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1,128,10000,1255394,1093841,77846 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1,256,8662,1023898,916324,65390 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1,512,10000,1116866,1017457,72413 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1,1024,8236,815912,736624,52294 diff --git a/testdata/output4.csv b/testdata/output4.csv new file mode 100644 index 0000000..a8b1845 --- /dev/null +++ b/testdata/output4.csv @@ -0,0 +1,155 @@ +name,parallelism,operations,duration,frequency,bytes_per_op,allocs_per_op +Select1,1,790153,1495,668896.3210702341,168,12 +Select1,2,1345888,926.5,1079330.8148947651,168,12 +Select1,4,1029002,1028,972762.6459143969,188,12 +Select1,8,869827,1360,735294.1176470588,185,12 +Select1,16,545296,1952,512295.08196721313,189,12 +Select1,32,547129,2153,464468.1839294008,193,12 +Select1,64,518738,2284,437828.37127845886,195,12 +Select1,128,418438,2505,399201.59680638724,196,12 +Select1,256,412849,2716,368188.5125184094,198,13 +Select1,512,367188,2967,337040.78193461406,201,13 +Select1,1024,323995,3346,298864.31560071727,204,13 +DB_ReadPost/mutex_false,1,106851,10855,92123.4454168586,5064,70 +DB_ReadPost/mutex_false,2,184839,6378,156788.96205707118,5064,70 +DB_ReadPost/mutex_false,4,255727,4621,216403.37589266393,5072,70 +DB_ReadPost/mutex_false,8,186601,6734,148500.1485001485,5117,71 +DB_ReadPost/mutex_false,16,118801,9543,104788.85046631038,5143,72 +DB_ReadPost/mutex_false,32,126266,10449,95702.93808019906,5153,73 +DB_ReadPost/mutex_false,64,87142,12151,82297.75327133569,5173,73 +DB_ReadPost/mutex_false,128,75932,14635,68329.3474547318,5188,74 +DB_ReadPost/mutex_false,256,71932,15458,64691.42191745374,5222,74 +DB_ReadPost/mutex_false,512,71619,19066,52449.386342179794,5277,75 +DB_ReadPost/mutex_false,1024,64186,17347,57646.85536403989,5270,75 +DB_ReadPost/mutex_true,1,103255,10907,91684.23947923353,5064,70 +DB_ReadPost/mutex_true,2,185330,6205,161160.35455278002,5064,70 +DB_ReadPost/mutex_true,4,260004,4542,220167.32716864816,5074,70 +DB_ReadPost/mutex_true,8,176294,6872,145518.04423748545,5121,71 +DB_ReadPost/mutex_true,16,110013,9815,101884.87009679063,5142,72 +DB_ReadPost/mutex_true,32,108694,10602,94321.82607055272,5152,73 +DB_ReadPost/mutex_true,64,83280,13206,75723.15614114796,5179,73 +DB_ReadPost/mutex_true,128,87104,13786,72537.35673872044,5192,74 +DB_ReadPost/mutex_true,256,78757,17134,58363.48780203105,5238,75 +DB_ReadPost/mutex_true,512,71954,16031,62379.14041544507,5235,74 +DB_ReadPost/mutex_true,1024,67196,16484,60664.887163309875,5259,75 +DB_WritePost/mutex_false,1,36357,30772,32497.07526322631,3992,22 +DB_WritePost/mutex_false,2,37180,29474,33928.20791205808,3992,22 +DB_WritePost/mutex_false,4,32991,30380,32916.392363396975,3992,22 +DB_WritePost/mutex_false,8,36916,28763,34766.8880158537,3992,22 +DB_WritePost/mutex_false,16,36807,32934,30363.75781866764,3992,22 +DB_WritePost/mutex_false,32,33592,36169,27647.985844231247,3993,22 +DB_WritePost/mutex_false,64,30153,39105,25572.177470911647,3996,22 +DB_WritePost/mutex_false,128,9181,139202,7183.804830390368,4017,22 +DB_WritePost/mutex_false,256,1071,1013229,986.9437215081684,4410,35 +DB_WritePost/mutex_false,512,1748,585838,1706.9565306449906,4587,38 +DB_WritePost/mutex_false,1024,1171,880128,1136.1983711460152,5790,66 +DB_WritePost/mutex_true,1,37920,30144,33174.09766454352,3992,22 +DB_WritePost/mutex_true,2,38636,30683,32591.337222566242,3992,22 +DB_WritePost/mutex_true,4,28395,40384,24762.28209191759,3992,22 +DB_WritePost/mutex_true,8,28808,40272,24831.14819229241,3993,22 +DB_WritePost/mutex_true,16,29643,40757,24535.662585568123,3994,22 +DB_WritePost/mutex_true,32,30112,38741,25812.446761828553,3993,22 +DB_WritePost/mutex_true,64,29664,38403,26039.632320391636,3993,22 +DB_WritePost/mutex_true,128,30157,39709,25183.207837014277,3993,22 +DB_WritePost/mutex_true,256,23594,48219,20738.712955473984,3994,22 +DB_WritePost/mutex_true,512,25057,48119,20781.811758349093,3996,22 +DB_WritePost/mutex_true,1024,34506,33607,29755.705656559647,3998,22 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01,1,19478,111816,8943.263933605209,26677,1617 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01,2,37039,103416,9669.683607952347,43744,2845 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01,4,65499,86358,11579.703096412608,67702,4623 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01,8,80562,84669,11810.698130366485,86565,6039 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01,16,68466,72408,13810.628659816595,79267,5471 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01,32,71906,72345,13822.655332089294,79347,5496 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01,64,59551,57229,17473.65845987174,60165,4096 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01,128,59228,63038,15863.447444398616,63485,4319 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01,256,53848,67016,14921.809717082488,65556,4480 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01,512,45206,52034,19218.20348233847,50496,3357 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.01,1024,35100,48329,20691.51027333485,40763,2603 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1,1,10000,489216,2044.086865515437,113297,7985 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1,2,10000,253993,3937.1163772229943,111447,7858 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1,4,10000,147819,6765.030205859869,113389,7994 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1,8,17343,182012,5494.143243302639,187002,13390 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1,16,12104,128664,7772.181806876826,135394,9635 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1,32,10000,102599,9746.68369087418,105050,7388 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1,64,10000,104560,9563.88676358072,108341,7618 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1,128,10000,101213,9880.15373519212,100018,7009 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1,256,10000,105364,9490.907710413423,102519,7188 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1,512,10000,121744,8213.957155999475,102152,7158 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_0.1,1024,10000,117114,8538.688798948033,101494,7109 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1,1,10000,4675206,213.89431823966686,1119965,79760 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1,2,10000,2582670,387.1961961845687,1119739,79744 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1,4,5805,856084,1168.109671480836,646712,46154 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1,8,5210,580638,1722.2434632249353,577437,41331 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1,16,4800,516089,1937.6502890005406,530896,37926 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1,32,4851,498834,2004.6749018711635,533080,38087 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1,64,4603,501852,1992.6193379721512,499405,35614 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1,128,3414,402022,2487.426061260329,351933,25193 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1,256,2062,587665,1701.6497494320745,177435,12654 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1,512,1000,1131322,883.9216421142698,47263,3037 +DB_ReadPostAndMaybeWriteComment/mutex_false/comment_rate_1,1024,1813,744656,1342.9019574138931,102558,7065 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01,1,17838,104167,9599.969280098303,24994,1494 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01,2,38834,109734,9112.945850875754,48091,3175 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01,4,66880,103785,9635.303752950811,78966,5464 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01,8,44755,54003,18517.489769086904,48802,3227 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01,16,34405,49750,20100.502512562813,36652,2320 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01,32,25586,62076,16109.285392100006,31154,1934 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01,64,22818,64795,15433.28960567945,28769,1760 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01,128,26546,62908,15896.229414382908,27604,1672 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01,256,30226,48744,20515.345478417858,21346,1212 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01,512,31393,40450,24721.878862793572,12903,615 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.01,1024,24115,51386,19460.553458140348,8247,281 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1,1,10000,490641,2038.150093449182,110553,7783 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1,2,10000,249135,4013.888052662211,103567,7278 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1,4,10000,178316,5608.021714260078,112517,7920 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1,8,10000,177056,5647.930598228809,116813,8221 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1,16,10000,212731,4700.772336894952,108290,7569 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1,32,10000,217131,4605.514643233808,111280,7794 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1,64,10000,206609,4840.060210349016,102449,7150 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1,128,10000,190087,5260.749025446243,91471,6356 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1,256,10000,167718,5962.389248619706,66593,4520 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1,512,10000,122500,8163.265306122449,35825,2270 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_0.1,1024,24273,218542,4575.779484035105,104321,7244 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1,1,10000,4740601,210.94371789568453,1119965,79760 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1,2,10000,4461101,224.15991030017028,1119738,79744 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1,4,10000,4482083,223.11054926916793,1119284,79712 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1,8,10000,4471042,223.66150888316415,1118377,79648 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1,16,9495,4244922,235.57558890363592,1057632,75497 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1,32,8308,3706785,269.77556022267277,920787,65747 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1,64,3537,1581670,632.2431354201572,378268,27084 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1,128,10000,4461710,224.12931364880282,1091493,77762 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1,256,4496,1858876,537.9594981053067,446386,31788 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1,512,6118,2408634,415.173081505949,573481,40917 +DB_ReadPostAndMaybeWriteComment/mutex_true/comment_rate_1,1024,9177,3422506,292.18356373955226,809698,57778 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01,1,21085,117309,8524.495136775524,27685,1685 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01,2,43975,101870,9816.432708353785,45042,2942 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01,4,78451,111886,8937.668698496684,87857,6133 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01,8,76304,76784,13023.546572202542,78314,5418 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01,16,69585,86344,11581.580654127676,81991,5685 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01,32,63589,77846,12845.87518947666,72992,5016 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01,64,55986,67619,14788.74280897381,63156,4293 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01,128,53895,69871,14312.089421934708,60694,4133 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01,256,46215,59630,16770.08217340265,49458,3287 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01,512,43458,56761,17617.730483959058,50406,3341 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.01,1024,28617,46028,21725.90597027896,34658,2168 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1,1,10000,522792,1912.806622901651,118176,8352 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1,2,10000,247172,4045.765701616688,102583,7218 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1,4,10000,148170,6749.00452183303,112700,7951 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1,8,10000,105121,9512.847100008561,105284,7408 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1,16,10000,108965,9177.258752810536,114157,8048 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1,32,10000,105095,9515.20053285123,107728,7585 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1,64,10000,100849,9915.81473291753,101855,7133 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1,128,12560,129951,7695.208193857685,124671,8851 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1,256,15062,133866,7470.156723888067,125743,8861 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1,512,19910,150991,6622.911299348968,143425,10208 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_0.1,1024,17707,88389,11313.624998585798,67253,4569 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1,1,10000,4974384,201.02991646804912,1119966,79760 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1,2,9831,2797821,357.4210072767343,1100069,78392 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1,4,10000,1585898,630.5575768428992,1119320,79713 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1,8,10000,1158135,863.457196268138,1118490,79652 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1,16,9338,1054451,948.360805765275,1039173,74240 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1,32,10000,1140638,876.7023367624084,1113942,79305 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1,64,10000,1181683,846.2506442083029,1107369,78835 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1,128,10000,1255394,796.5626727545297,1093841,77846 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1,256,8662,1023898,976.6597844707188,916324,65390 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1,512,10000,1116866,895.3625591610811,1017457,72413 +DB_ReadPostAndMaybeWriteCommentWithPool/comment_rate_1,1024,8236,815912,1225.622371040014,736624,52294 From b25c95dfe8d5a9f402ef838ad27b3a89602f5ad6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20W=C3=BCstenberg?= Date: Fri, 17 Nov 2023 13:36:22 +0100 Subject: [PATCH 2/3] Small fixes --- bench2csv.go | 9 ++++++--- bench2csv_test.go | 14 +++++++++++++- cmd/bench2csv/main.go | 4 ++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/bench2csv.go b/bench2csv.go index 5cf54a1..25ded38 100644 --- a/bench2csv.go +++ b/bench2csv.go @@ -18,11 +18,11 @@ const ( BytesPerOp AllocsPerOp Default = Name | Parallelism | Operations | Duration - Mem = BytesPerOp | AllocsPerOp + Memory = BytesPerOp | AllocsPerOp ) // benchmarkMatcher matches a benchmark output line. -// See https://regex101.com/r/Uv4LNN/latest +// See https://regex101.com/r/EEQMWQ/latest var benchmarkMatcher = regexp.MustCompile( `^Benchmark` + // "Benchmark" prefix `(?P[^-\s]+)` + // Name @@ -39,7 +39,10 @@ var benchmarkMatcher = regexp.MustCompile( `\sB/op\s+` + // Bytes per operation unit suffix `(?P\d+)` + // Allocs per operation `\sallocs/op` + // Allocs per operation unit suffix - `)?$`) + `)?` + + + // The end + `$`) // Process benchmark output from in, write CSV to csvOut, and pipe benchmark output to errOut. func Process(in io.Reader, csvOut, errOut io.Writer, format int) error { diff --git a/bench2csv_test.go b/bench2csv_test.go index ee048df..b9246f2 100644 --- a/bench2csv_test.go +++ b/bench2csv_test.go @@ -40,7 +40,7 @@ func TestProcess(t *testing.T) { var csv strings.Builder err := bench2csv.Process(strings.NewReader(readFile(t, "input2.txt")), &csv, io.Discard, - bench2csv.Default|bench2csv.Mem) + bench2csv.Default|bench2csv.Memory) noErr(t, err) if csv.String() != readFile(t, "output3.csv") { @@ -48,6 +48,18 @@ func TestProcess(t *testing.T) { } }) + t.Run("outputs CSV with benchmem statistics and frequency if set", func(t *testing.T) { + var csv strings.Builder + + err := bench2csv.Process(strings.NewReader(readFile(t, "input2.txt")), &csv, io.Discard, + bench2csv.Default|bench2csv.Frequency|bench2csv.Memory) + noErr(t, err) + + if csv.String() != readFile(t, "output4.csv") { + t.Fatal("Unexpected output:", csv.String()) + } + }) + t.Run("pipes input to output", func(t *testing.T) { input := readFile(t, "input1.txt") diff --git a/cmd/bench2csv/main.go b/cmd/bench2csv/main.go index 4542302..806d7c9 100644 --- a/cmd/bench2csv/main.go +++ b/cmd/bench2csv/main.go @@ -19,7 +19,7 @@ func start() error { format := bench2csv.Default freq := flag.Bool("freq", false, "Include frequency output") - mem := flag.Bool("mem", false, "Include -benchmem statistics output") + mem := flag.Bool("mem", false, "Include -benchmem output") flag.Parse() @@ -28,7 +28,7 @@ func start() error { } if *mem { - format |= bench2csv.Mem + format |= bench2csv.Memory } return bench2csv.Process(os.Stdin, os.Stdout, os.Stderr, format) From 3922174ddca884704345fb3e6065056d395b0ff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20W=C3=BCstenberg?= Date: Fri, 17 Nov 2023 13:40:36 +0100 Subject: [PATCH 3/3] Add benchmem to readme --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 4689ec6..7a37c37 100644 --- a/README.md +++ b/README.md @@ -22,4 +22,19 @@ PASS ok github.com/maragudk/go-bench2csv 7.324s ``` +Also works with `go test -benchmem`: + +```shell +$ go test -cpu 1,2,4,8 -bench . -benchmem | bench2csv -mem >benchmark.csv +goos: darwin +goarch: arm64 +pkg: github.com/maragudk/go-bench2csv +BenchmarkProcess/in_parallel_just_for_fun 4106 292497 ns/op 53892 B/op 738 allocs/op +BenchmarkProcess/in_parallel_just_for_fun-2 7929 151227 ns/op 53897 B/op 738 allocs/op +BenchmarkProcess/in_parallel_just_for_fun-4 15013 79910 ns/op 53909 B/op 738 allocs/op +BenchmarkProcess/in_parallel_just_for_fun-8 18214 66196 ns/op 53941 B/op 738 allocs/op +PASS +ok github.com/maragudk/go-bench2csv 7.402s +``` + Made in 🇩🇰 by [maragu](https://www.maragu.dk/), maker of [online Go courses](https://www.golang.dk/).