Skip to content

Instantly share code, notes, and snippets.

@9bow
Created May 4, 2021 00:57
Show Gist options
  • Save 9bow/92d2355a59ccf1facc5faac067387f03 to your computer and use it in GitHub Desktop.
Save 9bow/92d2355a59ccf1facc5faac067387f03 to your computer and use it in GitHub Desktop.
Benchmark Golang float32 conversion
$ go test -run ^$ -bench Benchmark -count 10 | tee sprint1.txt
goos: darwin
goarch: amd64
pkg: github.com/9bow/go-test-bmt-float32-to-str
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
BenchmarkFormatFloatPWithJoin-16 7291 138532 ns/op 69585 B/op 2050 allocs/op
BenchmarkFormatFloatPWithJoin-16 9146 135195 ns/op 69584 B/op 2050 allocs/op
BenchmarkFormatFloatPWithJoin-16 8947 135255 ns/op 69584 B/op 2050 allocs/op
BenchmarkFormatFloatPWithJoin-16 8982 134507 ns/op 69584 B/op 2050 allocs/op
BenchmarkFormatFloatPWithJoin-16 8881 133829 ns/op 69585 B/op 2050 allocs/op
BenchmarkFormatFloatPWithJoin-16 9082 133170 ns/op 69584 B/op 2050 allocs/op
BenchmarkFormatFloatPWithJoin-16 9049 133484 ns/op 69584 B/op 2050 allocs/op
BenchmarkFormatFloatPWithJoin-16 8258 133321 ns/op 69585 B/op 2050 allocs/op
BenchmarkFormatFloatPWithJoin-16 8832 132598 ns/op 69585 B/op 2050 allocs/op
BenchmarkFormatFloatPWithJoin-16 8917 134648 ns/op 69585 B/op 2050 allocs/op
BenchmarkFormatFloatSWithJoin-16 9054 134920 ns/op 70928 B/op 2050 allocs/op
BenchmarkFormatFloatSWithJoin-16 9308 131128 ns/op 70929 B/op 2050 allocs/op
BenchmarkFormatFloatSWithJoin-16 9163 130254 ns/op 70928 B/op 2050 allocs/op
BenchmarkFormatFloatSWithJoin-16 9318 131076 ns/op 70929 B/op 2050 allocs/op
BenchmarkFormatFloatSWithJoin-16 8326 130664 ns/op 70929 B/op 2050 allocs/op
BenchmarkFormatFloatSWithJoin-16 9102 131160 ns/op 70928 B/op 2050 allocs/op
BenchmarkFormatFloatSWithJoin-16 8854 131249 ns/op 70929 B/op 2050 allocs/op
BenchmarkFormatFloatSWithJoin-16 7861 134201 ns/op 70929 B/op 2050 allocs/op
BenchmarkFormatFloatSWithJoin-16 9296 131757 ns/op 70929 B/op 2050 allocs/op
BenchmarkFormatFloatSWithJoin-16 8536 131684 ns/op 70928 B/op 2050 allocs/op
BenchmarkSprintfFWithJoin-16 5190 226623 ns/op 42522 B/op 2050 allocs/op
BenchmarkSprintfFWithJoin-16 5149 226091 ns/op 42522 B/op 2050 allocs/op
BenchmarkSprintfFWithJoin-16 4690 227037 ns/op 42523 B/op 2050 allocs/op
BenchmarkSprintfFWithJoin-16 5299 228824 ns/op 42521 B/op 2050 allocs/op
BenchmarkSprintfFWithJoin-16 5078 225646 ns/op 42521 B/op 2050 allocs/op
BenchmarkSprintfFWithJoin-16 5174 226567 ns/op 42522 B/op 2050 allocs/op
BenchmarkSprintfFWithJoin-16 5238 225719 ns/op 42521 B/op 2050 allocs/op
BenchmarkSprintfFWithJoin-16 5031 226959 ns/op 42521 B/op 2050 allocs/op
BenchmarkSprintfFWithJoin-16 5077 227663 ns/op 42521 B/op 2050 allocs/op
BenchmarkSprintfFWithJoin-16 5173 224745 ns/op 42522 B/op 2050 allocs/op
BenchmarkSprintfVWithJoin-16 6542 180925 ns/op 45079 B/op 2050 allocs/op
BenchmarkSprintfVWithJoin-16 6362 179031 ns/op 45079 B/op 2050 allocs/op
BenchmarkSprintfVWithJoin-16 6592 179757 ns/op 45078 B/op 2050 allocs/op
BenchmarkSprintfVWithJoin-16 6652 178116 ns/op 45078 B/op 2050 allocs/op
BenchmarkSprintfVWithJoin-16 6506 179408 ns/op 45079 B/op 2050 allocs/op
BenchmarkSprintfVWithJoin-16 6556 178815 ns/op 45078 B/op 2050 allocs/op
BenchmarkSprintfVWithJoin-16 6496 178916 ns/op 45079 B/op 2050 allocs/op
BenchmarkSprintfVWithJoin-16 6486 178533 ns/op 45079 B/op 2050 allocs/op
BenchmarkSprintfVWithJoin-16 6480 177993 ns/op 45079 B/op 2050 allocs/op
BenchmarkSprintfVWithJoin-16 6499 181105 ns/op 45079 B/op 2050 allocs/op
BenchmarkFormatFloatPWithAdd-16 1507 799591 ns/op 5683632 B/op 3071 allocs/op
BenchmarkFormatFloatPWithAdd-16 1452 798786 ns/op 5683633 B/op 3071 allocs/op
BenchmarkFormatFloatPWithAdd-16 1494 802964 ns/op 5683631 B/op 3071 allocs/op
BenchmarkFormatFloatPWithAdd-16 1473 805781 ns/op 5683630 B/op 3071 allocs/op
BenchmarkFormatFloatPWithAdd-16 1467 810518 ns/op 5683634 B/op 3071 allocs/op
BenchmarkFormatFloatPWithAdd-16 1502 801709 ns/op 5683632 B/op 3071 allocs/op
BenchmarkFormatFloatPWithAdd-16 1470 802862 ns/op 5683631 B/op 3071 allocs/op
BenchmarkFormatFloatPWithAdd-16 1484 803274 ns/op 5683632 B/op 3071 allocs/op
BenchmarkFormatFloatPWithAdd-16 1477 809837 ns/op 5683634 B/op 3071 allocs/op
BenchmarkFormatFloatPWithAdd-16 1461 799149 ns/op 5683633 B/op 3071 allocs/op
BenchmarkFormatFloatSWithAdd-16 1323 891646 ns/op 6665217 B/op 3071 allocs/op
BenchmarkFormatFloatSWithAdd-16 1338 889966 ns/op 6665217 B/op 3071 allocs/op
BenchmarkFormatFloatSWithAdd-16 1336 892139 ns/op 6665217 B/op 3071 allocs/op
BenchmarkFormatFloatSWithAdd-16 1341 885443 ns/op 6665216 B/op 3071 allocs/op
BenchmarkFormatFloatSWithAdd-16 1326 903905 ns/op 6665218 B/op 3071 allocs/op
BenchmarkFormatFloatSWithAdd-16 1347 890137 ns/op 6665218 B/op 3071 allocs/op
BenchmarkFormatFloatSWithAdd-16 1332 887820 ns/op 6665217 B/op 3071 allocs/op
BenchmarkFormatFloatSWithAdd-16 1328 894675 ns/op 6665217 B/op 3071 allocs/op
BenchmarkFormatFloatSWithAdd-16 1341 891743 ns/op 6665218 B/op 3071 allocs/op
BenchmarkFormatFloatSWithAdd-16 1330 900618 ns/op 6665219 B/op 3071 allocs/op
BenchmarkSprintfFWithAdd-16 1406 842003 ns/op 4656593 B/op 3076 allocs/op
BenchmarkSprintfFWithAdd-16 1394 851386 ns/op 4656624 B/op 3076 allocs/op
BenchmarkSprintfFWithAdd-16 1390 842945 ns/op 4656628 B/op 3076 allocs/op
BenchmarkSprintfFWithAdd-16 1399 847411 ns/op 4656613 B/op 3076 allocs/op
BenchmarkSprintfFWithAdd-16 1369 847280 ns/op 4656630 B/op 3076 allocs/op
BenchmarkSprintfFWithAdd-16 1404 848374 ns/op 4656607 B/op 3076 allocs/op
BenchmarkSprintfFWithAdd-16 1402 839248 ns/op 4656628 B/op 3076 allocs/op
BenchmarkSprintfFWithAdd-16 1406 851368 ns/op 4656627 B/op 3076 allocs/op
BenchmarkSprintfFWithAdd-16 1155 877071 ns/op 4656886 B/op 3077 allocs/op
BenchmarkSprintfFWithAdd-16 1183 879329 ns/op 4656855 B/op 3077 allocs/op
BenchmarkSprintfVWithAdd-16 1165 900992 ns/op 5661354 B/op 3077 allocs/op
BenchmarkSprintfVWithAdd-16 1363 874857 ns/op 5661093 B/op 3076 allocs/op
BenchmarkSprintfVWithAdd-16 1303 874044 ns/op 5661172 B/op 3076 allocs/op
BenchmarkSprintfVWithAdd-16 1369 883500 ns/op 5661067 B/op 3076 allocs/op
BenchmarkSprintfVWithAdd-16 1119 904583 ns/op 5661430 B/op 3077 allocs/op
BenchmarkSprintfVWithAdd-16 1342 877645 ns/op 5661114 B/op 3076 allocs/op
BenchmarkSprintfVWithAdd-16 1359 878194 ns/op 5661091 B/op 3076 allocs/op
BenchmarkSprintfVWithAdd-16 1353 875793 ns/op 5661098 B/op 3076 allocs/op
BenchmarkSprintfVWithAdd-16 1350 882598 ns/op 5661109 B/op 3076 allocs/op
BenchmarkSprintfVWithAdd-16 1350 876092 ns/op 5661102 B/op 3076 allocs/op
PASS
$ benchstat sprint1.txt
name time/op
FormatFloatPWithJoin-16 134µs ± 1%
FormatFloatSWithJoin-16 131µs ± 1%
SprintfFWithJoin-16 227µs ± 1%
SprintfVWithJoin-16 179µs ± 1%
FormatFloatPWithAdd-16 803µs ± 1%
FormatFloatSWithAdd-16 892µs ± 1%
SprintfFWithAdd-16 846µs ± 1%
SprintfVWithAdd-16 878µs ± 1%
name alloc/op
FormatFloatPWithJoin-16 69.6kB ± 0%
FormatFloatSWithJoin-16 70.9kB ± 0%
SprintfFWithJoin-16 42.5kB ± 0%
SprintfVWithJoin-16 45.1kB ± 0%
FormatFloatPWithAdd-16 5.68MB ± 0%
FormatFloatSWithAdd-16 6.67MB ± 0%
SprintfFWithAdd-16 4.66MB ± 0%
SprintfVWithAdd-16 5.66MB ± 0%
name allocs/op
FormatFloatPWithJoin-16 2.05k ± 0%
FormatFloatSWithJoin-16 2.05k ± 0%
SprintfFWithJoin-16 2.05k ± 0%
SprintfVWithJoin-16 2.05k ± 0%
FormatFloatPWithAdd-16 3.07k ± 0%
FormatFloatSWithAdd-16 3.07k ± 0%
SprintfFWithAdd-16 3.08k ± 0%
SprintfVWithAdd-16 3.08k ± 0%
package main
import (
"fmt"
"strconv"
"strings"
"testing"
)
func GetVector() ([]float32, int) {
// 256-vector
// vector := []float32{0.04074662, 0.07717144, -0.01387950, 0.01287790, 0.04414229, 0.03390900, 0.03808868, 0.03956917, 0.00592308, -0.00935156, 0.04414903, -0.01830893, -0.01918902, 0.00154574, -0.02383651, -0.01054291, 0.12655860, 0.02075430, 0.10315673, 0.01371782, 0.01522089, 0.04304991, 0.03376650, 0.06703991, 0.03827063, -0.00063873, 0.02516229, 0.07061137, 0.08456459, -0.04103030, 0.03004974, 0.00297395, 0.00295535, 0.01112351, 0.02805021, 0.04350155, -0.00448326, 0.04780317, 0.10815978, -0.01784242, 0.03320745, 0.02912348, 0.00183310, 0.05318154, 0.00922967, -0.04507693, 0.01333585, 0.00048346, -0.04612860, 0.00427735, 0.01232839, -0.00100568, 0.03865110, 0.01765136, -0.00942758, 0.02383475, -0.01068696, 0.08959154, 0.08527020, 0.03379998, -0.03852739, 0.00607160, 0.01309861, -0.01262910, 0.00418265, 0.03614477, -0.02971224, 0.03703139, 0.04333942, -0.03143747, 0.06752674, -0.02173617, 0.03583429, 0.07731125, -0.02637132, -0.00395790, -0.04447101, 0.03351297, 0.08787052, 0.00647665, 0.03660145, -0.00640601, -0.01004024, 0.00763107, 0.04762240, -0.00068071, 0.00863653, 0.06126453, 0.04588475, -0.03891076, 0.07472295, 0.02470182, 0.08828569, 0.01660202, 0.02419317, 0.09363404, 0.05495216, 0.01202847, 0.00120040, -0.02136896, 0.03100559, 0.07371868, 0.00986731, 0.03934553, 0.01289396, 0.04705510, -0.02040175, 0.01501585, 0.00678832, 0.03882410, 0.02261387, 0.02165552, -0.05097445, 0.00240807, -0.04210005, 0.00760698, -0.02904095, 0.06572093, 0.03549200, 0.06070529, 0.06948626, 0.02832109, 0.01669887, 0.00914011, -0.00024529, -0.00124402, 0.06481186, 0.08246713, 0.07499877, 0.13112830, 0.01034968, 0.04224777, 0.01175614, 0.07395388, 0.04937797, 0.01561183, -0.03251049, 0.05449009, 0.04767901, -0.01149555, -0.02055555, -0.05990825, 0.06633005, 0.07592525, -0.04504610, 0.03348448, 0.04178635, 0.01327751, 0.02208084, 0.08780535, -0.00799043, 0.02236966, 0.01560906, 0.01171102, 0.00814554, -0.00257578, 0.08387835, -0.01018093, -0.02170087, 0.03230520, 0.00955880, -0.01824543, 0.05438962, 0.01805668, 0.02112979, -0.01372666, -0.01057472, 0.05453142, 0.03742066, 0.05534794, 0.00977020, 0.01991821, -0.00884413, 0.09644359, 0.02875310, 0.10519003, 0.05280351, -0.01918891, 0.03197290, 0.02722778, 0.03450845, 0.02669794, 0.08618007, 0.09387484, 0.05103674, -0.01431658, 0.00783211, -0.00434245, 0.02062620, -0.00611403, 0.06696083, 0.01333337, -0.00156842, 0.04325287, -0.05481976, 0.01642864, -0.02679648, -0.00642413, 0.03808333, 0.06134293, 0.06049823, 0.03818581, 0.03599750, -0.01651556, 0.06601544, 0.01385061, 0.00730943, 0.03045858, -0.00200028, 0.04009718, 0.04393080, -0.02568381, -0.01271287, -0.01860873, 0.03669106, 0.00154059, -0.04202117, 0.07374570, -0.00380450, 0.03164477, 0.00637422, -0.02361638, 0.01918917, 0.01680134, 0.01346881, 0.02424449, -0.00504802, -0.06241146, 0.08241857, 0.02817723, 0.02132487, 0.08051144, 0.06332499, 0.02585857, -0.04057337, 0.00279212, -0.00005161, -0.06566417, 0.07860317, -0.01276221, 0.06822366, -0.00191142, 0.08534018, 0.06014366, 0.07053877, -0.01962799, 0.08602677, -0.00817098, 0.00302233, -0.10041475, -0.01908947, 0.03235617, 0.00931559, 0.05451865, 0.02233902, -0.01173994}
// 1024-vector
vector := []float32{0.03900551, 0.00917545, -0.03127822, 0.00646266, -0.00913413, -0.03260259, -0.02070184, 0.04090960, 0.04538678, 0.01820286, 0.07799997, -0.02246271, -0.00816716, -0.01384671, 0.01869069, 0.11457775, 0.05020951, 0.00683059, 0.04868238, 0.00390586, 0.03942839, -0.01556312, -0.07234249, -0.03452188, -0.01337260, 0.05977351, 0.05435626, -0.02089527, 0.07733323, 0.05846843, -0.02229896, 0.01156832, -0.01862785, 0.01612830, 0.02806288, -0.00852489, 0.00957779, 0.04038851, -0.04090206, 0.00733118, -0.01862884, 0.08980903, -0.01484485, 0.00419364, 0.01898987, 0.05336608, 0.01904166, -0.00939173, 0.03687233, 0.00555669, 0.02244642, 0.03856312, 0.08115652, 0.05935441, 0.01755458, 0.06525502, -0.02553919, 0.05739566, 0.04427762, 0.03826257, 0.02370865, 0.03405447, 0.04718409, 0.02602869, -0.00668003, 0.04249606, 0.01225620, 0.04930680, 0.00176888, 0.00956789, 0.03193902, 0.08768127, 0.04002526, -0.03961443, 0.08617344, 0.02053219, -0.00641649, 0.07934313, 0.03245073, 0.04263123, -0.02142718, 0.02461455, 0.01369116, 0.04167211, 0.00112262, 0.03681254, 0.06228955, -0.00734138, -0.02493375, 0.00132630, 0.02324780, 0.05652186, 0.06926157, 0.05095699, 0.02389788, 0.01257757, 0.01174677, 0.02990630, 0.02415842, 0.04712655, -0.01685437, 0.07034504, 0.00170934, 0.05469075, 0.03532000, 0.00977561, 0.07503991, 0.00679969, 0.11002573, 0.03389606, 0.05538719, -0.01522707, 0.03384871, 0.03338322, 0.03825954, 0.05236718, 0.02176397, -0.02997180, 0.04561907, 0.00930261, 0.00396412, 0.00878776, 0.07156089, 0.08124831, 0.02014908, 0.02055424, 0.01650204, 0.01749159, 0.06634506, -0.00396060, 0.07948820, 0.01710440, 0.04641368, 0.04033798, -0.00840505, 0.05127066, 0.00828432, 0.02584113, 0.01373709, 0.03851754, 0.06202960, 0.00057146, 0.01250418, -0.02708583, 0.01276608, 0.01558878, 0.05840690, 0.01532591, 0.06267338, 0.06839507, 0.03520037, 0.02901214, -0.05149586, -0.02698674, 0.00225538, 0.04838537, 0.00121991, -0.01654669, -0.00587732, -0.00128831, 0.05412380, 0.08379419, 0.06195482, 0.00040350, 0.00925233, 0.03006378, 0.09479256, 0.00269849, 0.01127352, 0.04021394, -0.00723479, -0.08621317, 0.06785519, 0.00746428, 0.02511213, 0.01366785, -0.04097094, 0.08341448, 0.04936603, 0.08499184, 0.04229953, 0.01409627, 0.03874146, 0.02455029, 0.01904072, 0.03813811, -0.00681226, -0.04479592, 0.02013930, 0.00901011, 0.02198651, 0.01656315, 0.01766456, -0.00819600, 0.06555627, 0.00538510, 0.00663667, 0.00258791, 0.02357219, 0.00159932, 0.00149627, 0.04839014, -0.00466380, -0.01091476, 0.03904770, 0.01843971, 0.00458209, 0.02846965, 0.00649227, 0.00402771, -0.05378851, 0.01155723, -0.02828310, 0.03096337, -0.00151846, -0.02087678, 0.05247780, 0.00460581, -0.01592737, -0.00257877, 0.01428015, 0.08214080, 0.00587064, 0.01688759, 0.00611408, -0.02492411, -0.01879199, 0.03307675, -0.03868258, 0.08697144, 0.00718878, 0.05879258, 0.04642537, 0.05356763, -0.00259983, 0.03144253, 0.06523529, 0.03033498, -0.03725293, 0.04192665, 0.00990371, 0.08392441, 0.07756414, 0.01108572, 0.02569188, -0.00145452, 0.00497646, 0.02613271, 0.05394439, 0.05464096, 0.01493141, 0.05863366, 0.08137169, 0.00381633, 0.06122092, -0.01055475, 0.02571679, 0.01016951, -0.03117778, 0.01244072, 0.01448744, -0.00762566, -0.02980741, 0.02018110, 0.02296758, 0.02819578, 0.05638361, -0.05958832, -0.02149538, -0.00621482, 0.00629240, 0.08364259, 0.02236798, -0.01278309, 0.03940233, 0.02014312, 0.00895460, -0.01558432, -0.08109383, -0.02872617, 0.00457938, 0.02488889, 0.03000590, -0.05088162, 0.03004097, 0.06388319, 0.04562659, 0.01923873, 0.00522451, 0.02135419, 0.05662539, -0.02034701, 0.01000408, 0.03458463, -0.03945235, 0.00796498, -0.02189193, 0.07680909, 0.00258892, -0.02647941, 0.03283003, 0.08782904, 0.02541256, 0.03602448, 0.03806052, -0.01045260, 0.01961751, 0.01630193, 0.05889183, 0.01676574, 0.05192704, 0.06603909, 0.02460998, 0.07035533, 0.02850222, 0.07853191, -0.04589904, 0.02237599, 0.04764792, 0.00695705, -0.00386305, 0.04473344, 0.03661080, 0.08156495, -0.01700848, -0.01723638, 0.03637049, 0.07775442, 0.01825737, -0.04298615, 0.08227650, -0.00967971, 0.02095576, 0.09339749, 0.05777365, 0.00639847, 0.04391575, 0.00063554, -0.01886419, 0.05747194, 0.03470673, 0.03395129, 0.06511635, -0.01647345, 0.00036920, 0.01138065, 0.02709559, 0.04843768, 0.06829076, 0.03837208, 0.01497785, -0.04113594, 0.01643627, 0.04789764, 0.05065099, 0.08857917, -0.01993816, 0.04180630, 0.00071169, 0.03807720, 0.04957095, 0.02190355, 0.01755720, 0.00363709, 0.06637681, 0.05508344, 0.05651485, 0.01942745, 0.06411707, -0.00680655, 0.03056427, 0.07193972, 0.00294636, -0.02038956, 0.03596566, -0.02797827, 0.03257278, 0.00640804, 0.03389193, 0.06229533, 0.02721200, -0.01709400, 0.05770140, -0.01938860, 0.04637470, 0.05021776, 0.05297751, 0.01155687, 0.08502885, 0.02769619, 0.00162373, 0.00755096, 0.00850964, 0.06504896, -0.01481909, 0.02578931, 0.08488325, 0.02947102, 0.02751591, -0.00986994, 0.02930389, -0.04609594, -0.01094113, -0.01097271, 0.10511363, 0.06824764, -0.00697551, 0.01404899, -0.04471179, -0.01753995, -0.00890031, 0.06281195, -0.02306196, 0.02856090, 0.03366600, 0.00324529, 0.02363313, 0.08878582, 0.08314038, 0.05910319, 0.02628800, 0.04280899, 0.04326558, 0.00698666, -0.00319410, 0.04991100, 0.05506867, -0.06958511, 0.06416979, 0.00832396, 0.00993626, 0.04543190, -0.02396029, 0.03977937, 0.04663058, 0.05884408, 0.03344898, 0.00588855, 0.02377201, -0.00180749, 0.03913332, 0.00938531, 0.02495954, -0.05614496, 0.02392644, 0.00995163, 0.01098763, 0.03329684, 0.02658073, 0.02546460, 0.05395766, -0.00692787, -0.03132951, 0.04947728, -0.01551526, 0.01497149, -0.01996353, 0.03710527, 0.02347682, 0.05262319, 0.00041361, 0.05013321, 0.02478895, 0.01003219, -0.00182465, -0.00060485, -0.00747279, 0.00521512, 0.03999216, 0.04653218, 0.05008745, -0.01320988, 0.04966363, -0.03507639, -0.00719651, -0.03802902, 0.00539831, 0.06128297, 0.00780295, 0.02286809, -0.01353430, -0.02170432, -0.01125894, -0.01089930, -0.00292189, 0.06667755, 0.05340438, 0.02934769, 0.07005157, 0.08023050, -0.04887071, 0.01343469, 0.01957501, 0.03140340, -0.06046190, 0.01370401, 0.03533877, 0.06923307, 0.02746986, -0.03324708, 0.04359799, -0.00801021, 0.04631326, 0.02076471, 0.01294299, 0.02920960, -0.00470591, 0.08165351, 0.09182668, -0.01760344, 0.08880094, 0.01490533, 0.02642577, 0.06930449, 0.04015196, -0.00166214, 0.01232266, -0.01446517, -0.00405165, 0.04685187, 0.01671137, 0.04519900, 0.02547936, -0.02664107, 0.03313552, 0.01927316, -0.01828470, 0.10568012, -0.01976019, 0.02031940, 0.05725530, -0.03933045, 0.00084281, -0.04040306, -0.02978378, 0.06482577, 0.00287737, 0.04543236, 0.02859370, -0.02324720, 0.01191857, 0.04226068, -0.04864452, -0.00869803, -0.00861635, 0.01282910, 0.05721350, 0.00745467, -0.02100822, 0.03715871, 0.00559424, -0.00172484, -0.00609966, 0.11770537, -0.01384855, -0.00375274, 0.06035750, 0.09190076, 0.02770989, 0.01642074, -0.01865564, -0.03695710, 0.03244358, 0.03780009, 0.05145099, -0.00702317, -0.01753389, 0.05790094, 0.05463789, 0.05807445, 0.03319873, 0.03171148, -0.00752112, -0.00773008, 0.04718160, -0.02857119, 0.01685171, 0.05755646, 0.00764634, 0.05886038, -0.06453750, -0.02932066, 0.08199658, 0.07298535, 0.07826779, -0.02053427, 0.11669852, -0.01349856, -0.00795009, 0.04354671, 0.04444684, -0.01888153, -0.01115854, -0.02873208, -0.00793399, 0.00887259, 0.04310139, 0.06669466, 0.06551094, -0.01358486, -0.03300229, -0.00663807, 0.04756468, 0.02085567, 0.06257220, 0.02524139, 0.03449119, 0.02553396, 0.04008548, 0.01982218, 0.01973251, 0.05013191, -0.05220337, 0.08970957, 0.00826163, 0.04836064, 0.01870750, -0.01132981, 0.05048301, 0.01217563, 0.03144075, 0.03934437, 0.05089497, 0.01974510, 0.05733895, -0.00041031, 0.07643560, 0.04289042, 0.02222787, 0.01529651, 0.01434759, 0.02009845, 0.03093337, 0.02765874, -0.00647710, 0.04772557, 0.04897580, 0.01896258, 0.01723670, 0.01587990, 0.02789631, -0.03960808, 0.07839771, 0.05843030, 0.04046960, -0.01174963, 0.00583507, 0.02108049, 0.02956509, 0.00718686, -0.00685037, 0.02668014, 0.07182842, 0.06235739, 0.03073130, -0.00034457, 0.01669844, 0.03615847, 0.01505424, 0.00585322, 0.05079744, 0.01245061, 0.00248933, -0.00298464, -0.04358787, 0.00699385, 0.02965781, 0.04979002, -0.03904180, 0.00035203, 0.00956558, 0.02329582, 0.05591733, 0.05009513, 0.07175804, 0.05335635, 0.01786522, 0.02229192, 0.09166357, -0.01706442, 0.01396294, 0.05101503, -0.03297922, -0.03334126, 0.05122231, 0.01247852, -0.01990404, 0.00376896, -0.03116595, 0.04225019, 0.03404762, 0.06113519, 0.06277544, 0.02770864, 0.05151761, 0.03731882, 0.06510640, 0.03423817, 0.02189811, -0.06066413, 0.00610071, -0.01592611, -0.05734472, 0.02369288, 0.06153009, -0.03347005, 0.02180784, 0.01807523, 0.02072567, 0.05331801, 0.00437190, -0.01449957, 0.01109982, 0.07925148, 0.02312274, 0.02049571, 0.05987411, -0.01330148, 0.03209545, 0.08226530, -0.06285828, 0.01689138, -0.04720628, -0.01505437, 0.00205337, -0.00271966, 0.02164694, -0.02572868, 0.06299975, 0.01082820, 0.03654403, 0.01606774, -0.02115103, 0.04621043, 0.03654101, 0.02527170, 0.00311718, 0.01539506, 0.00425238, 0.07448684, -0.01475243, 0.02312316, 0.04930264, 0.05178524, -0.00880173, 0.02856706, -0.02059043, -0.00348088, 0.10349221, 0.07561888, -0.01689476, 0.02452000, 0.03311075, 0.04420938, 0.07473315, -0.01771782, 0.05142215, -0.02632481, 0.02892594, -0.01648114, 0.01801129, 0.09188704, 0.03351933, 0.03960171, 0.06194539, -0.01628624, 0.08236267, 0.05492759, 0.06167243, 0.02266737, -0.00894878, 0.00003346, 0.02997522, 0.00983530, -0.00601817, 0.00821857, 0.04319080, 0.02475497, 0.03495369, -0.03316386, -0.01109961, -0.00077172, -0.00607015, 0.10668542, 0.03731576, 0.01856950, 0.05344721, 0.01784593, -0.00194894, -0.04771554, -0.03510017, -0.03828712, 0.03412211, 0.02307255, 0.01763161, -0.02252374, 0.03644318, 0.04244433, 0.01278565, 0.02829077, -0.00688183, 0.01352117, 0.03375096, 0.01028597, -0.03708988, 0.11171588, -0.01071868, 0.00680160, -0.00390113, 0.08327544, -0.03826688, 0.03807302, 0.03284309, 0.07962735, 0.04530309, 0.00550020, 0.05100409, -0.00076518, 0.03285329, -0.01795122, 0.04532417, -0.00142261, 0.04151542, 0.06163811, 0.01588554, 0.06079155, 0.07788803, 0.05249190, 0.00650894, 0.03919972, 0.04479008, 0.02731665, 0.00346025, 0.01882261, 0.03794450, 0.06612604, 0.01055724, -0.03043247, 0.04404556, 0.06530055, 0.02952459, -0.02580743, 0.07378547, -0.01880116, 0.00594179, 0.06150476, 0.03314291, -0.00507209, -0.01153939, -0.00778410, -0.05007529, 0.05918916, 0.03792871, 0.06825603, 0.05127934, 0.01614159, -0.00996914, -0.00089163, 0.05500453, 0.04235454, 0.10082226, 0.05505812, 0.02949821, -0.03275904, 0.00624757, 0.04208685, 0.00410008, 0.08767135, -0.02149976, 0.09634293, 0.04265287, 0.00685210, 0.04095491, 0.00356232, 0.02460479, 0.03412595, 0.06772134, 0.06934305, 0.06959572, 0.05158476, 0.05586613, 0.04757794, 0.05107395, 0.02855568, -0.03081628, 0.01341314, 0.07592261, 0.02487875, 0.03441551, -0.00101682, 0.03280345, 0.08008535, 0.06322445, -0.03481483, 0.02125791, 0.03695528, 0.02988247, 0.02474139, 0.06648855, 0.02654533, 0.06538644, 0.05837247, 0.01790783, 0.03148698, 0.01015087, 0.03851603, 0.01414420, -0.00146022, 0.07523835, 0.00009444, 0.04257409, -0.01041669, 0.00984051, -0.02689407, -0.00016836, -0.01473922, 0.09643257, -0.00163737, 0.00487313, 0.02246208, -0.00787784, -0.01846550, 0.02170371, 0.06288873, 0.03035631, 0.01340867, 0.02158830, -0.01391086, 0.01817904, 0.05353072, 0.08148737, 0.06018165, 0.03894427, 0.01210258, 0.08043820, 0.01356921, -0.01470825, 0.05505395, 0.02391436, -0.06149739, 0.04296087, 0.02577026, -0.01576786, 0.04894597, 0.01700762, 0.04495736, 0.05879998, 0.03580890, 0.05691220, -0.01860054, -0.01495803, 0.00782435, 0.03600916, 0.02363319, -0.00244135, -0.04599632, 0.02626805, 0.01681293, -0.01933066, 0.02051396, 0.00147382, -0.00745928, 0.07861513, -0.01235996, -0.01870328, 0.05984193, -0.00003587, -0.00912307, -0.01137245, 0.03686146, 0.06886361, 0.03613527, 0.05281575, 0.02174967, 0.05056422, 0.01021691, 0.02169936, 0.01936193, -0.05123442, -0.02061994, 0.01228918, -0.01943587, 0.04299153, -0.02686793, -0.00139507, -0.01177218, 0.01092568, 0.02459783, 0.03787782, 0.05915877, 0.00988554, 0.01656184, -0.00843561, -0.03045062, 0.01696731, -0.00110651, -0.00110352, 0.05960581, 0.04494532, 0.05042335, 0.09326071, 0.02701996, -0.00677179, 0.01658810, -0.01157500, 0.02525374, -0.03951447, 0.02712421, 0.03139326, 0.04834440, 0.04754756, 0.00199653, 0.02173882, -0.01347014, 0.04056982, 0.02231991, 0.02119047, 0.01919195, 0.03123732, 0.06686745, 0.06187204, -0.01342191, 0.10279418, 0.03652679}
vecLen := len(vector)
return vector, vecLen
}
func BenchmarkFormatFloatPWithJoin(b *testing.B) {
b.ReportAllocs()
vals := make([]string, b.N)
vector, vecLen := GetVector()
for i := 0; i < b.N; i++ {
tmpVecStr := make([]string, vecLen)
for tmpVecIdx, tmpVecItem := range vector {
tmpVecStr[tmpVecIdx] = strconv.FormatFloat(float64(tmpVecItem), 'f', -1, 32)
}
vals[i] = strings.Join(tmpVecStr, ",")
}
}
func BenchmarkFormatFloatSWithJoin(b *testing.B) {
b.ReportAllocs()
vals := make([]string, b.N)
vector, vecLen := GetVector()
for i := 0; i < b.N; i++ {
tmpVecStr := make([]string, vecLen)
for tmpVecIdx, tmpVecItem := range vector {
tmpVecStr[tmpVecIdx] = strconv.FormatFloat(float64(tmpVecItem), 'E', -1, 32)
}
vals[i] = strings.Join(tmpVecStr, ",")
}
}
func BenchmarkSprintfFWithJoin(b *testing.B) {
b.ReportAllocs()
vals := make([]string, b.N)
vector, vecLen := GetVector()
for i := 0; i < b.N; i++ {
tmpVecStr := make([]string, vecLen)
for tmpVecIdx, tmpVecItem := range vector {
tmpVecStr[tmpVecIdx] = fmt.Sprintf("%f", tmpVecItem)
}
vals[i] = strings.Join(tmpVecStr, ",")
}
}
func BenchmarkSprintfVWithJoin(b *testing.B) {
b.ReportAllocs()
vals := make([]string, b.N)
vector, vecLen := GetVector()
for i := 0; i < b.N; i++ {
tmpVecStr := make([]string, vecLen)
for tmpVecIdx, tmpVecItem := range vector {
tmpVecStr[tmpVecIdx] = fmt.Sprintf("%v", tmpVecItem)
}
vals[i] = strings.Join(tmpVecStr, ",")
}
}
func BenchmarkFormatFloatPWithAdd(b *testing.B) {
b.ReportAllocs()
vals := make([]string, b.N)
vector, _ := GetVector()
for i := 0; i < b.N; i++ {
var tmpVecStr string
for _, tmpVecItem := range vector {
tmpVecStr = tmpVecStr + strconv.FormatFloat(float64(tmpVecItem), 'f', -1, 32)
}
vals[i] = tmpVecStr
}
}
func BenchmarkFormatFloatSWithAdd(b *testing.B) {
b.ReportAllocs()
vals := make([]string, b.N)
vector, _ := GetVector()
for i := 0; i < b.N; i++ {
var tmpVecStr string
for _, tmpVecItem := range vector {
tmpVecStr = tmpVecStr + strconv.FormatFloat(float64(tmpVecItem), 'E', -1, 32)
}
vals[i] = tmpVecStr
}
}
func BenchmarkSprintfFWithAdd(b *testing.B) {
b.ReportAllocs()
vals := make([]string, b.N)
vector, _ := GetVector()
for i := 0; i < b.N; i++ {
var tmpVecStr string
for _, tmpVecItem := range vector {
tmpVecStr = tmpVecStr + fmt.Sprintf("%f", tmpVecItem)
}
vals[i] = tmpVecStr
}
}
func BenchmarkSprintfVWithAdd(b *testing.B) {
b.ReportAllocs()
vals := make([]string, b.N)
vector, _ := GetVector()
for i := 0; i < b.N; i++ {
var tmpVecStr string
for _, tmpVecItem := range vector {
tmpVecStr = tmpVecStr + fmt.Sprintf("%v", tmpVecItem)
}
vals[i] = tmpVecStr
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment