On Mon, May 31, 2021 at 3:30 PM tapi...@gmail.com <tapir....@gmail.com> wrote:
> On Sunday, May 30, 2021 at 12:54:02 PM UTC-4 axel.wa...@googlemail.com > wrote: > >> That is very normal for micro-benchmarks on a ns scale. >> > The results are so constantly that I think it is more related to CPU cache > and the specified directives. > Yes that's what I meant. Given that the signal is so small (on a ns scale), noise introduced by alignment and code caches and other micro-architectural details becomes so large (relatively), that it's normal to notice an effect in reordering or removing unrelated code. That's why they are not a good basis to base decisions on. You can't know if what you're seeing is a real effect or just noise. > > >> >> On Sun, May 30, 2021 at 6:07 PM tapi...@gmail.com <tapi...@gmail.com> >> wrote: >> >>> It is some strange that if any of the bool/byte/int16/int64 benchmarks >>> is removed in this test file https://play.golang.org/p/w29J9VhtzYH, >>> then the benchmark result is like: >>> >>> Benchmark_CopyStruct_3_fields-4 1000000000 0.7780 ns/op >>> Benchmark_CopyStruct_4_fields-4 1000000000 0.7513 ns/op >>> >>> Otherwise, it is like: >>> >>> Benchmark_CopyStruct_3_fields-4 1000000000 1.501 ns/op >>> Benchmark_CopyStruct_4_fields-4 1000000000 0.7755 ns/op >>> >>> In other words, it looks there is mutual interference between benchmarks. >>> >>> On Saturday, May 29, 2021 at 11:49:47 PM UTC-4 tapi...@gmail.com wrote: >>> >>>> The benchmark code: https://play.golang.org/p/bC1zO14eNeh >>>> >>>> The result: >>>> >>>> $ go test -bench=. >>>> goos: linux >>>> goarch: amd64 >>>> pkg: example.com/valuecopy >>>> cpu: Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz >>>> Benchmark_CopyBool-4 1000000000 0.8885 >>>> ns/op >>>> Benchmark_CopyByte-4 1000000000 0.8872 >>>> ns/op >>>> Benchmark_CopyInt16-4 1000000000 0.8785 >>>> ns/op >>>> Benchmark_CopyInt32-4 1000000000 0.8854 >>>> ns/op >>>> Benchmark_CopyInt64-4 1000000000 0.8831 >>>> ns/op >>>> Benchmark_CopyPointer-4 911733464 1.330 >>>> ns/op >>>> Benchmark_CopyString-4 901249356 1.325 >>>> ns/op >>>> Benchmark_CopySlice-4 664187247 1.765 >>>> ns/op >>>> Benchmark_CopyArray_2_elements-4 1000000000 0.8874 >>>> ns/op >>>> Benchmark_CopyArray_3_elements-4 1000000000 1.096 >>>> ns/op >>>> Benchmark_CopyArray_4_elements-4 1000000000 1.105 >>>> ns/op >>>> Benchmark_CopyArray_5_elements-4 534542524 2.202 >>>> ns/op >>>> Benchmark_CopyArray_6_elements-4 727849554 1.606 >>>> ns/op >>>> Benchmark_CopyArray_7_elements-4 444494692 2.649 >>>> ns/op >>>> Benchmark_CopyArray_8_elements-4 584854867 1.993 >>>> ns/op >>>> Benchmark_CopyArray_9_elements-4 389639859 3.083 >>>> ns/op >>>> Benchmark_CopyArray_10_elements-4 267380602 4.418 >>>> ns/op >>>> Benchmark_CopyArray_11_elements-4 242644033 4.867 >>>> ns/op >>>> Benchmark_CopyArray_12_elements-4 268304104 4.498 >>>> ns/op >>>> Benchmark_CopyArray_13_elements-4 82165272 14.46 ns/op >>>> Benchmark_CopyStruct_2_fields-4 1000000000 0.5029 >>>> ns/op >>>> Benchmark_CopyStruct_3_fields-4 671136589 1.769 >>>> ns/op >>>> Benchmark_CopyStruct_4_fields-4 1000000000 0.8785 >>>> ns/op >>>> Benchmark_CopyStruct_5_fields-4 530876049 2.202 >>>> ns/op >>>> Benchmark_CopyStruct_6_fields-4 723380257 1.581 >>>> ns/op >>>> Benchmark_CopyStruct_7_fields-4 444619906 2.636 >>>> ns/op >>>> Benchmark_CopyStruct_8_fields-4 588605260 1.968 >>>> ns/op >>>> Benchmark_CopyStruct_9_fields-4 387253551 3.073 >>>> ns/op >>>> Benchmark_CopyStruct_10_fields-4 267450452 4.396 >>>> ns/op >>>> Benchmark_CopyStruct_11_fields-4 246289522 4.855 >>>> ns/op >>>> Benchmark_CopyStruct_12_fields-4 266212528 4.426 >>>> ns/op >>>> Benchmark_CopyStruct_13_fields-4 207298701 5.739 >>>> ns/op >>>> >>>> From the benchmark result, it looks >>>> * the cost of copying a [13]int value is much larger than copying a >>>> [12]int value. >>>> * the cost of copying a struct{a, b, c int} value is about double of >>>> copying a struct{a, b, c, d int} value. >>>> >>>> >>>> -- >>> You received this message because you are subscribed to the Google >>> Groups "golang-nuts" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to golang-nuts...@googlegroups.com. >>> >> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/golang-nuts/f53a8f05-37a6-4c86-87c1-de9e83f381fdn%40googlegroups.com >>> <https://groups.google.com/d/msgid/golang-nuts/f53a8f05-37a6-4c86-87c1-de9e83f381fdn%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/6caafbc0-66f3-4b77-ac92-6174b17ebf30n%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/6caafbc0-66f3-4b77-ac92-6174b17ebf30n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAEkBMfH8vMvBdhAiy9iH%3D3dEYHOc-SoCZ_s%2BHFNHtFqDNxVdhg%40mail.gmail.com.