Nice. The example output on your github page is still wrong, cycles count is 
much too high.

Min cycle count seems to be 4 for most simple procs, but that is no problem. I 
have just tested a plain string comparison -- about 100 cycles, as expected 
from its C code. So string comparison is not a very cheap operation in Nim -- 
not too surprising, as special nil case has to be considered.
    
    
    import criterion
    
    var cfg = newDefaultConfig()
    
    benchmark cfg:
      
      proc t0() {.measure.} =
        var a = "Rust"
        var b = "Nim"
        doAssert a != b
      
      proc t1() {.measure.} =
        var a = "Rust"
        var b = "Nim"
        doAssert a > b
    
    
    Run
    
    
    $ ./t
    Benchmark: t0()
    Collected 277 samples
    Warning: Found 4 mild and 8 extreme outliers in the time measurements
    Warning: Found 4 mild and 6 extreme outliers in the cycles measurements
    Time
      Mean:  42.4753ns (41.2772ns .. 43.8444ns)
      Std:   11.6368ns (7.6329ns .. 16.4890ns)
      Slope: 42.2136ns (41.7204ns .. 42.9674ns)
      r^2:   0.9977 (0.9960 .. 0.9988)
    Cycles
      Mean:  108cycles (105cycles .. 111cycles)
      Std:   25cycles (18cycles .. 33cycles)
      Slope: 109cycles (108cycles .. 111cycles)
      r^2:   0.9977 (0.9958 .. 0.9988)
    
    Benchmark: t1()
    Collected 275 samples
    Warning: Found 21 mild and 5 extreme outliers in the time measurements
    Warning: Found 2 mild and 3 extreme outliers in the cycles measurements
    Time
      Mean:  42.1040ns (41.2619ns .. 42.9831ns)
      Std:   7.4068ns (5.1946ns .. 10.0585ns)
      Slope: 48.4274ns (46.7242ns .. 49.9679ns)
      r^2:   0.9934 (0.9891 .. 0.9968)
    Cycles
      Mean:  107cycles (105cycles .. 109cycles)
      Std:   15cycles (13cycles .. 17cycles)
      Slope: 125cycles (121cycles .. 129cycles)
      r^2:   0.9934 (0.9886 .. 0.9966)
    
    
    
    Run

C code looks like
    
    
    static N_INLINE(NIM_BOOL, eqStrings)(NimStringDesc* a, NimStringDesc* b) {
            NIM_BOOL result;
            NI alen;
            NI blen;
    {       result = (NIM_BOOL)0;
            {
                    if (!(a == b)) goto LA3_;
                    result = NIM_TRUE;
                    goto BeforeRet_;
            }
            LA3_: ;
            {
                    if (!(a == NIM_NIL)) goto LA7_;
                    alen = ((NI) 0);
            }
            goto LA5_;
            LA7_: ;
            {
                    alen = (*a).Sup.len;
            }
            LA5_: ;
            {
                    if (!(b == NIM_NIL)) goto LA12_;
                    blen = ((NI) 0);
            }
            goto LA10_;
            LA12_: ;
            {
                    blen = (*b).Sup.len;
            }
            LA10_: ;
            {
                    if (!(alen == blen)) goto LA17_;
                    {
                            if (!(alen == ((NI) 0))) goto LA21_;
                            result = NIM_TRUE;
                            goto BeforeRet_;
                    }
                    LA21_: ;
                    result = equalMem_fmeFeLBvgmAHG9bC8ETS9bYQt(((void*) 
((*a).data)), ((void*) ((*b).data)), ((NI) (alen)));
                    goto BeforeRet_;
            }
            LA17_: ;
            }BeforeRet_: ;
            return result;
    }
    
    
    
    Run

Reply via email to