tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

spreadcall-optimization.js (1016B)


      1 // Test case adapted from "apply-optimization.js" to test SpreadCall instead of FunApply.
      2 
      3 // Uses fewer iterations than "apply-optimization.js" to keep the overall runtime reasonable.
      4 const iterations = 40;
      5 
      6 function make(k) {
      7    var a = new Array(k);
      8    for ( let i=0 ; i < k ; i++ )
      9        a[i] = {}
     10    return a;
     11 }
     12 
     13 function g() {
     14    return arguments.length;
     15 }
     16 
     17 function f(a) {
     18    var sum = 0;
     19    for ( let i=0 ; i < iterations ; i++ )
     20        sum += g(...a);
     21    return sum;
     22 }
     23 
     24 function time(k, t) {
     25    var then = Date.now();
     26    assertEq(t(), iterations*k);
     27    var now = Date.now();
     28    return now - then;
     29 }
     30 
     31 function p(v) {
     32    // Uncomment to see timings
     33    // print(v);
     34 }
     35 
     36 f(make(200));
     37 
     38 // There is currently a cutoff after 375 where we bailout in order to avoid
     39 // handling very large stack frames.  This slows the operation down by a factor
     40 // of 100 or so.
     41 
     42 p(time(374, () => f(make(374))));
     43 p(time(375, () => f(make(375))));
     44 p(time(376, () => f(make(376))));
     45 p(time(377, () => f(make(377))));