On 02/02/2017 09:27, Ian Davis wrote:

On Thu, 2 Feb 2017, at 09:20 AM, T L wrote:


On Thursday, February 2, 2017 at 4:58:32 PM UTC+8, Axel Wagner wrote:

    Hi,

    I can not really reproduce your results. I rewrote your code to
    use the builtin benchmarking: http://sprunge.us/IfQc
    Giving, on my laptop:

    BenchmarkAssertion-4 1000000000        2.89 ns/op
    BenchmarkAssertionOK-4 500000000        2.66 ns/op
    BenchmarkBare-4 1000000000        2.22 ns/op
    BenchmarkIface-4 50000000       30.0 ns/op
    BenchmarkReflect-4 200000000        9.74 ns/op

    Note, that a) yes, there is an overhead of the type-assertion,
    but b) it's pretty small, especially compared to the other things
    you're trying and c) it can be further reduced by using the
    two-value form (so that there is never a need to consider
    stack-unwinding).

    Overall, this smells like a micro-benchmark. I wouldn't worry too
    much about it until you have specific evidence that it's slowing
    down a real program.


The result on my machine for your test:
BenchmarkAssertion-4 500000000            17.9 ns/op
BenchmarkAssertionOK-4 500000000            17.9 ns/op
BenchmarkBare-4 2000000000             3.93 ns/op
BenchmarkIface-4 100000000            86.7 ns/op
BenchmarkReflect-4 500000000            15.6 ns/op

What version of Go and what OS/hardware?


Similar results here:
BenchmarkAssertion-24           100000000               14.4 ns/op
BenchmarkAssertionOK-24         100000000               14.0 ns/op
BenchmarkBare-24                1000000000               2.81 ns/op
BenchmarkIface-24               30000000                40.2 ns/op
BenchmarkReflect-24             100000000               13.2 ns/op

go version go1.7.5 freebsd/amd64

CPU: Intel(R) Xeon(R) CPU E5-2640 0 @ 2.50GHz (2500.06-MHz K8-class CPU)

    Regards
    Steve

--
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to