Skip to content

Commit a43e6e8

Browse files
committed
add template benchmarks
1 parent 454e723 commit a43e6e8

File tree

3 files changed

+220
-91
lines changed

3 files changed

+220
-91
lines changed

README.md

+163-90
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ In order for you to benefit from it too, I will publish such benchmarks in this
2525
* [parse](https://github.com/SimonWaldherr/golang-benchmarks#parse)
2626
* [random](https://github.com/SimonWaldherr/golang-benchmarks#random)
2727
* [regexp](https://github.com/SimonWaldherr/golang-benchmarks#regexp)
28+
* [template](https://github.com/SimonWaldherr/golang-benchmarks#template)
2829

2930
## Golang?
3031

@@ -95,10 +96,10 @@ func BenchmarkBase64regex(b *testing.B) {
9596
$ go test -bench . -benchmem
9697
goos: darwin
9798
goarch: arm64
98-
BenchmarkBase64decode-12 19996819 54.32 ns/op 32 B/op 2 allocs/op
99-
BenchmarkBase64regex-12 124668 9656 ns/op 21930 B/op 198 allocs/op
99+
BenchmarkBase64decode-12 22016134 54.08 ns/op 32 B/op 2 allocs/op
100+
BenchmarkBase64regex-12 122818 9754 ns/op 21934 B/op 198 allocs/op
100101
PASS
101-
ok _/Users/simonwaldherr/git/golang-benchmarks/base64 2.628s
102+
ok _/Users/simonwaldherr/git/golang-benchmarks/base64 3.621s
102103
```
103104

104105
### between
@@ -190,12 +191,12 @@ func BenchmarkFulltextParse(b *testing.B) {
190191
$ go test -bench . -benchmem
191192
goos: darwin
192193
goarch: arm64
193-
BenchmarkNumberRegEx-12 150912 6691 ns/op 16885 B/op 142 allocs/op
194-
BenchmarkFulltextRegEx-12 220384 5577 ns/op 12096 B/op 104 allocs/op
195-
BenchmarkNumberParse-12 34177120 36.02 ns/op 0 B/op 0 allocs/op
196-
BenchmarkFulltextParse-12 2583351 473.2 ns/op 32 B/op 2 allocs/op
194+
BenchmarkNumberRegEx-12 178830 6717 ns/op 16884 B/op 142 allocs/op
195+
BenchmarkFulltextRegEx-12 216558 5509 ns/op 12092 B/op 104 allocs/op
196+
BenchmarkNumberParse-12 33441436 36.00 ns/op 0 B/op 0 allocs/op
197+
BenchmarkFulltextParse-12 2600692 462.1 ns/op 32 B/op 2 allocs/op
197198
PASS
198-
ok _/Users/simonwaldherr/git/golang-benchmarks/between 5.487s
199+
ok _/Users/simonwaldherr/git/golang-benchmarks/between 6.554s
199200
```
200201

201202
### caseinsensitivecompare
@@ -237,11 +238,11 @@ func BenchmarkToLower(b *testing.B) {
237238
$ go test -bench . -benchmem
238239
goos: darwin
239240
goarch: arm64
240-
BenchmarkEqualFold-12 83169073 14.28 ns/op 0 B/op 0 allocs/op
241-
BenchmarkToUpper-12 11368695 104.5 ns/op 16 B/op 3 allocs/op
242-
BenchmarkToLower-12 8984072 133.8 ns/op 20 B/op 5 allocs/op
241+
BenchmarkEqualFold-12 83269279 14.19 ns/op 0 B/op 0 allocs/op
242+
BenchmarkToUpper-12 11273568 108.1 ns/op 16 B/op 3 allocs/op
243+
BenchmarkToLower-12 8712837 139.1 ns/op 20 B/op 5 allocs/op
243244
PASS
244-
ok _/Users/simonwaldherr/git/golang-benchmarks/caseinsensitivecompare 4.899s
245+
ok _/Users/simonwaldherr/git/golang-benchmarks/caseinsensitivecompare 4.773s
245246
```
246247

247248
### concat
@@ -287,11 +288,11 @@ func BenchmarkConcatBuilder(b *testing.B) {
287288
$ go test -bench . -benchmem
288289
goos: darwin
289290
goarch: arm64
290-
BenchmarkConcatString-12 1000000 25979 ns/op 503993 B/op 1 allocs/op
291-
BenchmarkConcatBuffer-12 316726768 3.862 ns/op 3 B/op 0 allocs/op
292-
BenchmarkConcatBuilder-12 566796470 2.227 ns/op 5 B/op 0 allocs/op
291+
BenchmarkConcatString-12 1000000 24151 ns/op 503993 B/op 1 allocs/op
292+
BenchmarkConcatBuffer-12 319202809 3.834 ns/op 3 B/op 0 allocs/op
293+
BenchmarkConcatBuilder-12 562989975 2.193 ns/op 5 B/op 0 allocs/op
293294
PASS
294-
ok _/Users/simonwaldherr/git/golang-benchmarks/concat 29.234s
295+
ok _/Users/simonwaldherr/git/golang-benchmarks/concat 27.378s
295296
```
296297

297298
### contains
@@ -441,16 +442,16 @@ func BenchmarkMatchNot(b *testing.B) {
441442
$ go test -bench . -benchmem
442443
goos: darwin
443444
goarch: arm64
444-
BenchmarkContains-12 243319177 4.730 ns/op 0 B/op 0 allocs/op
445-
BenchmarkContainsNot-12 203857521 5.952 ns/op 0 B/op 0 allocs/op
446-
BenchmarkContainsBytes-12 239583264 5.067 ns/op 0 B/op 0 allocs/op
447-
BenchmarkContainsBytesNot-12 193715023 6.245 ns/op 0 B/op 0 allocs/op
448-
BenchmarkCompileMatch-12 25531280 47.67 ns/op 0 B/op 0 allocs/op
449-
BenchmarkCompileMatchNot-12 48846096 24.97 ns/op 0 B/op 0 allocs/op
450-
BenchmarkMatch-12 1600905 733.2 ns/op 1400 B/op 17 allocs/op
451-
BenchmarkMatchNot-12 1709605 692.3 ns/op 1400 B/op 17 allocs/op
445+
BenchmarkContains-12 244669579 4.762 ns/op 0 B/op 0 allocs/op
446+
BenchmarkContainsNot-12 201522261 5.967 ns/op 0 B/op 0 allocs/op
447+
BenchmarkContainsBytes-12 233834960 5.122 ns/op 0 B/op 0 allocs/op
448+
BenchmarkContainsBytesNot-12 195563943 6.117 ns/op 0 B/op 0 allocs/op
449+
BenchmarkCompileMatch-12 25424962 47.24 ns/op 0 B/op 0 allocs/op
450+
BenchmarkCompileMatchNot-12 48151756 25.11 ns/op 0 B/op 0 allocs/op
451+
BenchmarkMatch-12 1645866 731.2 ns/op 1400 B/op 17 allocs/op
452+
BenchmarkMatchNot-12 1711884 700.2 ns/op 1400 B/op 17 allocs/op
452453
PASS
453-
ok _/Users/simonwaldherr/git/golang-benchmarks/contains 13.517s
454+
ok _/Users/simonwaldherr/git/golang-benchmarks/contains 13.492s
454455
```
455456

456457
### foreach
@@ -537,12 +538,12 @@ func BenchmarkRangeSliceKey(b *testing.B) {
537538
$ go test -bench . -benchmem
538539
goos: darwin
539540
goarch: arm64
540-
BenchmarkForMap-12 60349282 19.73 ns/op 0 B/op 0 allocs/op
541-
BenchmarkRangeMap-12 23453418 50.31 ns/op 0 B/op 0 allocs/op
542-
BenchmarkRangeSlice-12 444954975 2.625 ns/op 0 B/op 0 allocs/op
543-
BenchmarkRangeSliceKey-12 444752958 2.674 ns/op 0 B/op 0 allocs/op
541+
BenchmarkForMap-12 60544635 19.49 ns/op 0 B/op 0 allocs/op
542+
BenchmarkRangeMap-12 24341181 49.43 ns/op 0 B/op 0 allocs/op
543+
BenchmarkRangeSlice-12 458142114 2.615 ns/op 0 B/op 0 allocs/op
544+
BenchmarkRangeSliceKey-12 458975700 2.620 ns/op 0 B/op 0 allocs/op
544545
PASS
545-
ok _/Users/simonwaldherr/git/golang-benchmarks/foreach 6.329s
546+
ok _/Users/simonwaldherr/git/golang-benchmarks/foreach 6.332s
546547
```
547548

548549
### hash
@@ -749,37 +750,37 @@ func BenchmarkSHA256Parallel(b *testing.B) {
749750
$ go test -bench . -benchmem
750751
goos: darwin
751752
goarch: arm64
752-
BenchmarkAdler32-12 1736274 644.9 ns/op 8 B/op 1 allocs/op
753-
BenchmarkBCryptCost4-12 617988486 1.950 ns/op 0 B/op 0 allocs/op
754-
BenchmarkBCryptCost10-12 612595080 1.941 ns/op 0 B/op 0 allocs/op
755-
BenchmarkBCryptCost16-12 623830992 1.938 ns/op 0 B/op 0 allocs/op
756-
BenchmarkBlake2b256-12 467415 2487 ns/op 32 B/op 1 allocs/op
757-
BenchmarkBlake2b512-12 481509 2484 ns/op 64 B/op 1 allocs/op
758-
BenchmarkBlake3256-12 424382 2824 ns/op 64 B/op 2 allocs/op
759-
BenchmarkMMH3-12 3761997 319.6 ns/op 16 B/op 1 allocs/op
760-
BenchmarkCRC32-12 5076656 235.7 ns/op 8 B/op 1 allocs/op
761-
BenchmarkCRC64ISO-12 969268 1221 ns/op 8 B/op 1 allocs/op
762-
BenchmarkCRC64ECMA-12 978988 1271 ns/op 8 B/op 1 allocs/op
763-
BenchmarkFnv32-12 510414 2595 ns/op 8 B/op 1 allocs/op
764-
BenchmarkFnv32a-12 500038 2373 ns/op 8 B/op 1 allocs/op
765-
BenchmarkFnv64-12 514794 2341 ns/op 8 B/op 1 allocs/op
766-
BenchmarkFnv64a-12 514521 2341 ns/op 8 B/op 1 allocs/op
767-
BenchmarkFnv128-12 313018 4043 ns/op 16 B/op 1 allocs/op
768-
BenchmarkFnv128a-12 469338 2545 ns/op 16 B/op 1 allocs/op
769-
BenchmarkMD4-12 404767 2934 ns/op 24 B/op 2 allocs/op
770-
BenchmarkMD5-12 397561 2978 ns/op 16 B/op 1 allocs/op
771-
BenchmarkSHA1-12 1417716 839.9 ns/op 24 B/op 1 allocs/op
772-
BenchmarkSHA224-12 1397877 856.2 ns/op 32 B/op 1 allocs/op
773-
BenchmarkSHA256-12 1386200 849.4 ns/op 32 B/op 1 allocs/op
774-
BenchmarkSHA384-12 805606 1443 ns/op 48 B/op 1 allocs/op
775-
BenchmarkSHA512-12 843320 1467 ns/op 64 B/op 1 allocs/op
776-
BenchmarkSHA3256-12 226137 5279 ns/op 480 B/op 2 allocs/op
777-
BenchmarkSHA3512-12 129634 9239 ns/op 512 B/op 2 allocs/op
778-
BenchmarkRIPEMD160-12 200340 6007 ns/op 24 B/op 1 allocs/op
779-
BenchmarkWhirlpool-12 45129 26826 ns/op 64 B/op 1 allocs/op
780-
BenchmarkSHA256Parallel-12 13299388 96.35 ns/op 32 B/op 1 allocs/op
753+
BenchmarkAdler32-12 1755891 662.3 ns/op 8 B/op 1 allocs/op
754+
BenchmarkBCryptCost4-12 610794391 1.969 ns/op 0 B/op 0 allocs/op
755+
BenchmarkBCryptCost10-12 602775782 1.973 ns/op 0 B/op 0 allocs/op
756+
BenchmarkBCryptCost16-12 612259476 1.931 ns/op 0 B/op 0 allocs/op
757+
BenchmarkBlake2b256-12 471999 2506 ns/op 32 B/op 1 allocs/op
758+
BenchmarkBlake2b512-12 470184 2506 ns/op 64 B/op 1 allocs/op
759+
BenchmarkBlake3256-12 417142 2873 ns/op 64 B/op 2 allocs/op
760+
BenchmarkMMH3-12 3688101 330.7 ns/op 16 B/op 1 allocs/op
761+
BenchmarkCRC32-12 4858033 244.9 ns/op 8 B/op 1 allocs/op
762+
BenchmarkCRC64ISO-12 955809 1258 ns/op 8 B/op 1 allocs/op
763+
BenchmarkCRC64ECMA-12 948634 1247 ns/op 8 B/op 1 allocs/op
764+
BenchmarkFnv32-12 505034 2355 ns/op 8 B/op 1 allocs/op
765+
BenchmarkFnv32a-12 518242 2348 ns/op 8 B/op 1 allocs/op
766+
BenchmarkFnv64-12 513234 2354 ns/op 8 B/op 1 allocs/op
767+
BenchmarkFnv64a-12 511670 2363 ns/op 8 B/op 1 allocs/op
768+
BenchmarkFnv128-12 307057 3963 ns/op 16 B/op 1 allocs/op
769+
BenchmarkFnv128a-12 479191 2511 ns/op 16 B/op 1 allocs/op
770+
BenchmarkMD4-12 410452 2934 ns/op 24 B/op 2 allocs/op
771+
BenchmarkMD5-12 399772 3030 ns/op 16 B/op 1 allocs/op
772+
BenchmarkSHA1-12 1435189 832.4 ns/op 24 B/op 1 allocs/op
773+
BenchmarkSHA224-12 1438218 835.2 ns/op 32 B/op 1 allocs/op
774+
BenchmarkSHA256-12 1430865 851.0 ns/op 32 B/op 1 allocs/op
775+
BenchmarkSHA384-12 811088 1474 ns/op 48 B/op 1 allocs/op
776+
BenchmarkSHA512-12 804488 1481 ns/op 64 B/op 1 allocs/op
777+
BenchmarkSHA3256-12 227422 5252 ns/op 480 B/op 2 allocs/op
778+
BenchmarkSHA3512-12 129693 9124 ns/op 512 B/op 2 allocs/op
779+
BenchmarkRIPEMD160-12 204349 5888 ns/op 24 B/op 1 allocs/op
780+
BenchmarkWhirlpool-12 46082 26047 ns/op 64 B/op 1 allocs/op
781+
BenchmarkSHA256Parallel-12 12900202 93.69 ns/op 32 B/op 1 allocs/op
781782
PASS
782-
ok _/Users/simonwaldherr/git/golang-benchmarks/hash 40.505s
783+
ok _/Users/simonwaldherr/git/golang-benchmarks/hash 40.243s
783784
```
784785

785786
### index
@@ -888,12 +889,12 @@ func BenchmarkMapIntIndex(b *testing.B) {
888889
$ go test -bench . -benchmem
889890
goos: darwin
890891
goarch: arm64
891-
BenchmarkMapStringKeys-12 19577160 54.10 ns/op 0 B/op 0 allocs/op
892-
BenchmarkMapIntKeys-12 41623549 27.73 ns/op 0 B/op 0 allocs/op
893-
BenchmarkMapStringIndex-12 22315063 54.91 ns/op 0 B/op 0 allocs/op
894-
BenchmarkMapIntIndex-12 41915013 25.28 ns/op 0 B/op 0 allocs/op
892+
BenchmarkMapStringKeys-12 21331105 54.21 ns/op 0 B/op 0 allocs/op
893+
BenchmarkMapIntKeys-12 39508015 26.58 ns/op 0 B/op 0 allocs/op
894+
BenchmarkMapStringIndex-12 21212530 53.88 ns/op 0 B/op 0 allocs/op
895+
BenchmarkMapIntIndex-12 39205808 26.59 ns/op 0 B/op 0 allocs/op
895896
PASS
896-
ok _/Users/simonwaldherr/git/golang-benchmarks/index 6.628s
897+
ok _/Users/simonwaldherr/git/golang-benchmarks/index 5.374s
897898
```
898899

899900
### json
@@ -984,10 +985,10 @@ func BenchmarkJsonUnmarshal(b *testing.B) {
984985
$ go test -bench . -benchmem
985986
goos: darwin
986987
goarch: arm64
987-
BenchmarkJsonMarshal-12 1550515 748.4 ns/op 480 B/op 5 allocs/op
988-
BenchmarkJsonUnmarshal-12 327422 3756 ns/op 1816 B/op 27 allocs/op
988+
BenchmarkJsonMarshal-12 1690164 692.3 ns/op 480 B/op 5 allocs/op
989+
BenchmarkJsonUnmarshal-12 340788 3481 ns/op 1816 B/op 27 allocs/op
989990
PASS
990-
ok _/Users/simonwaldherr/git/golang-benchmarks/json 3.195s
991+
ok _/Users/simonwaldherr/git/golang-benchmarks/json 3.269s
991992
```
992993

993994
### math
@@ -1070,16 +1071,16 @@ func BenchmarkMathFloat64(b *testing.B) {
10701071
$ go test -bench . -benchmem
10711072
goos: darwin
10721073
goarch: arm64
1073-
BenchmarkMathInt8-12 1000000000 0.3023 ns/op 0 B/op 0 allocs/op
1074-
BenchmarkMathInt32-12 1000000000 0.3016 ns/op 0 B/op 0 allocs/op
1075-
BenchmarkMathInt64-12 1000000000 0.3124 ns/op 0 B/op 0 allocs/op
1076-
BenchmarkMathAtomicInt32-12 297988206 4.604 ns/op 0 B/op 0 allocs/op
1077-
BenchmarkMathAtomicInt64-12 287726745 4.017 ns/op 0 B/op 0 allocs/op
1078-
BenchmarkMathMutexInt-12 151071498 7.978 ns/op 0 B/op 0 allocs/op
1079-
BenchmarkMathFloat32-12 1000000000 0.2875 ns/op 0 B/op 0 allocs/op
1080-
BenchmarkMathFloat64-12 1000000000 0.2923 ns/op 0 B/op 0 allocs/op
1074+
BenchmarkMathInt8-12 1000000000 0.2944 ns/op 0 B/op 0 allocs/op
1075+
BenchmarkMathInt32-12 1000000000 0.2919 ns/op 0 B/op 0 allocs/op
1076+
BenchmarkMathInt64-12 1000000000 0.2930 ns/op 0 B/op 0 allocs/op
1077+
BenchmarkMathAtomicInt32-12 299367180 4.030 ns/op 0 B/op 0 allocs/op
1078+
BenchmarkMathAtomicInt64-12 296352517 4.063 ns/op 0 B/op 0 allocs/op
1079+
BenchmarkMathMutexInt-12 148652618 7.981 ns/op 0 B/op 0 allocs/op
1080+
BenchmarkMathFloat32-12 1000000000 0.2929 ns/op 0 B/op 0 allocs/op
1081+
BenchmarkMathFloat64-12 1000000000 0.2913 ns/op 0 B/op 0 allocs/op
10811082
PASS
1082-
ok _/Users/simonwaldherr/git/golang-benchmarks/math 7.171s
1083+
ok _/Users/simonwaldherr/git/golang-benchmarks/math 7.008s
10831084
```
10841085

10851086
### parse
@@ -1125,11 +1126,11 @@ func BenchmarkParseFloat(b *testing.B) {
11251126
$ go test -bench . -benchmem
11261127
goos: darwin
11271128
goarch: arm64
1128-
BenchmarkParseBool-12 1000000000 0.3024 ns/op 0 B/op 0 allocs/op
1129-
BenchmarkParseInt-12 122175952 9.851 ns/op 0 B/op 0 allocs/op
1130-
BenchmarkParseFloat-12 19506550 60.94 ns/op 0 B/op 0 allocs/op
1129+
BenchmarkParseBool-12 1000000000 0.2961 ns/op 0 B/op 0 allocs/op
1130+
BenchmarkParseInt-12 124657645 9.607 ns/op 0 B/op 0 allocs/op
1131+
BenchmarkParseFloat-12 20188128 59.26 ns/op 0 B/op 0 allocs/op
11311132
PASS
1132-
ok _/Users/simonwaldherr/git/golang-benchmarks/parse 3.927s
1133+
ok _/Users/simonwaldherr/git/golang-benchmarks/parse 3.911s
11331134
```
11341135

11351136
### random
@@ -1201,12 +1202,12 @@ func GenerateRandomString(s int) (string, error) {
12011202
$ go test -bench . -benchmem
12021203
goos: darwin
12031204
goarch: arm64
1204-
BenchmarkMathRand-12 172488864 6.813 ns/op 0 B/op 0 allocs/op
1205-
BenchmarkCryptoRand-12 3291207 359.5 ns/op 48 B/op 3 allocs/op
1206-
BenchmarkCryptoRandString-12 10238113 115.1 ns/op 128 B/op 3 allocs/op
1207-
BenchmarkCryptoRandBytes-12 19756704 60.27 ns/op 32 B/op 1 allocs/op
1205+
BenchmarkMathRand-12 171987848 6.831 ns/op 0 B/op 0 allocs/op
1206+
BenchmarkCryptoRand-12 3366360 355.0 ns/op 48 B/op 3 allocs/op
1207+
BenchmarkCryptoRandString-12 10739014 113.7 ns/op 128 B/op 3 allocs/op
1208+
BenchmarkCryptoRandBytes-12 20425836 58.36 ns/op 32 B/op 1 allocs/op
12081209
PASS
1209-
ok _/Users/simonwaldherr/git/golang-benchmarks/random 6.124s
1210+
ok _/Users/simonwaldherr/git/golang-benchmarks/random 6.172s
12101211
```
12111212

12121213
### regexp
@@ -1260,10 +1261,82 @@ func BenchmarkMatchStringGolibs(b *testing.B) {
12601261
$ go test -bench . -benchmem
12611262
goos: darwin
12621263
goarch: arm64
1263-
BenchmarkMatchString-12 254317 4348 ns/op 10230 B/op 86 allocs/op
1264-
BenchmarkMatchStringCompiled-12 3690358 318.8 ns/op 0 B/op 0 allocs/op
1265-
BenchmarkMatchStringGolibs-12 3776370 323.4 ns/op 0 B/op 0 allocs/op
1264+
BenchmarkMatchString-12 291122 4111 ns/op 10222 B/op 86 allocs/op
1265+
BenchmarkMatchStringCompiled-12 3766557 320.4 ns/op 0 B/op 0 allocs/op
1266+
BenchmarkMatchStringGolibs-12 3661724 330.3 ns/op 0 B/op 0 allocs/op
12661267
PASS
1267-
ok _/Users/simonwaldherr/git/golang-benchmarks/regexp 4.344s
1268+
ok _/Users/simonwaldherr/git/golang-benchmarks/regexp 5.334s
1269+
```
1270+
1271+
### template
1272+
1273+
```go
1274+
// Package template benchmarks the performance of different templating methods
1275+
package template
1276+
1277+
import (
1278+
"bytes"
1279+
htmltemplate "html/template"
1280+
"regexp"
1281+
"testing"
1282+
texttemplate "text/template"
1283+
)
1284+
1285+
// Define a struct to hold the data for the templates
1286+
type Data struct {
1287+
Name string
1288+
Address string
1289+
}
1290+
1291+
// Prepare the templates and data
1292+
var (
1293+
data = Data{Name: "John Doe", Address: "123 Elm St"}
1294+
1295+
textTplString = "Name: {{.Name}}, Address: {{.Address}}"
1296+
htmlTplString = "<div>Name: {{.Name}}</div><div>Address: {{.Address}}</div>"
1297+
regExpString = "Name: {{NAME}}, Address: {{ADDRESS}}"
1298+
)
1299+
1300+
// Benchmark for text/template
1301+
func BenchmarkTextTemplate(b *testing.B) {
1302+
tpl, _ := texttemplate.New("text").Parse(textTplString)
1303+
b.ResetTimer()
1304+
for i := 0; i < b.N; i++ {
1305+
var buf bytes.Buffer
1306+
tpl.Execute(&buf, data)
1307+
}
1308+
}
1309+
1310+
// Benchmark for html/template
1311+
func BenchmarkHTMLTemplate(b *testing.B) {
1312+
tpl, _ := htmltemplate.New("html").Parse(htmlTplString)
1313+
b.ResetTimer()
1314+
for i := 0; i < b.N; i++ {
1315+
var buf bytes.Buffer
1316+
tpl.Execute(&buf, data)
1317+
}
1318+
}
1319+
1320+
// Benchmark for replacing placeholders using regexp
1321+
func BenchmarkRegExp(b *testing.B) {
1322+
rName := regexp.MustCompile(`{{NAME}}`)
1323+
rAddress := regexp.MustCompile(`{{ADDRESS}}`)
1324+
b.ResetTimer()
1325+
for i := 0; i < b.N; i++ {
1326+
result := rName.ReplaceAllString(regExpString, data.Name)
1327+
result = rAddress.ReplaceAllString(result, data.Address)
1328+
}
1329+
}
1330+
```
1331+
1332+
```
1333+
$ go test -bench . -benchmem
1334+
goos: darwin
1335+
goarch: arm64
1336+
BenchmarkTextTemplate-12 3268081 352.7 ns/op 208 B/op 6 allocs/op
1337+
BenchmarkHTMLTemplate-12 986030 1187 ns/op 528 B/op 20 allocs/op
1338+
BenchmarkRegExp-12 2820849 420.3 ns/op 298 B/op 9 allocs/op
1339+
PASS
1340+
ok _/Users/simonwaldherr/git/golang-benchmarks/template 4.475s
12681341
```
12691342

0 commit comments

Comments
 (0)