[Webkit-unassigned] [Bug 36849] Add zero() method to Vector class

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Thu Apr 1 14:33:34 PDT 2010


https://bugs.webkit.org/show_bug.cgi?id=36849





--- Comment #22 from Chris Rogers <crogers at google.com>  2010-04-01 14:33:33 PST ---
> 
> 2) Is there any evidence that zeroFill() would measurably improve performance
> over fill(0)?
> 
> Regards,
> Maciej

memset() is definitely quite a bit faster than a straight zero-filling loop. 
It's tremendously optimized and its source code is quite interesting to read.

I created a quick benchmark to test my zero() method vs. fill():

    // Make sure memset() code is "hot" (so we're not measuring paging
activity)
    float temp[2048];
    memset(temp, 0, sizeof(float) * 2048);

    printf("            n       fill()     memset()   speed improvement\n");

    for (unsigned i = 0; i < 24; ++i) {
        const int k = 1UL << i;
        const int n = k * 128;
        Vector<float> v1(n);
        Vector<float> v2(n);
        v1.fill(1.0);
        v2.fill(1.0);
        PerformanceTimer timer1("fill  "); // PerformanceTimer internally uses
UpTime(), but could use mach_absolute_time()
        PerformanceTimer timer2("memset");
        timer1.Start();
        v1.fill(0.0);
        timer1.Stop(); // print elapsed time

        timer2.Start();
        v2.zero();
        timer2.Stop();

        // times in usec
        double time1 = timer1.GetElapsedTime();
        double time2 = timer2.GetElapsedTime();
        double speedUp = time1 / time2;
        printf("%14d %10.3f %10.3f %10.3f\n", n, time1, time2, speedUp);
    }


Here are the results run on the latest 8-core Xeon desktop Mac (laptops and ARM
chips would be somewhat slower):

            n       fill()     memset()   speed improvement
           128      0.291      0.223      1.305
           256      0.411      0.191      2.152
           512      0.712      0.218      3.266
          1024      0.902      0.194      4.649
          2048      1.760      0.329      5.350
          4096      3.299      0.691      4.774
          8192      6.531      1.397      4.675
         16384     13.029      2.825      4.612
         32768     26.016      6.163      4.221
         65536     56.320     16.795      3.353
        131072    107.894     33.843      3.188
        262144    207.663     65.043      3.193
        524288    415.301    131.098      3.168
       1048576    841.864    549.443      1.532
       2097152   1721.820   1280.595      1.345
       4194304   3377.447   2427.105      1.392
       8388608   6726.940   4902.623      1.372
      16777216  13458.201   9882.302      1.362
      33554432  26849.611  19685.213      1.364
      67108864  53677.435  39297.878      1.366
     134217728 107947.327  79122.879      1.364

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list