wujjpp opened a new pull request #2483:
URL: https://github.com/apache/thrift/pull/2483


   `Array.push` is more more effective `Array.concat`
   
   ```javascript
   const Benchmark = require('benchmark');
   
   const buffer = Buffer.alloc(1024)
   buffer.fill('A')
   const loop = 1024;
   
   const suite = new Benchmark.Suite()
   
   suite
     .add('buffer.concat', function () {
       let target = Buffer.alloc(0)
       for(let i = 0; i < loop; ++i){
         target = Buffer.concat([target, buffer], target.length + buffer.length)
       }
     })
     .add('Array.push', function () {
       const target = []
       for(let i = 0; i < loop; ++i){
         for(let j = 0; j < buffer.length; ++j){
           target.push(buffer[i])
         }
       }
     })
     .on('cycle', function(event) {
       console.log(String(event.target));
     })
     .on('complete', function() {
       console.log('Fastest is ' + this.filter('fastest').map('name'));
       // console.log(this)
     })
     .run({ async: true })
   ```
   
   results:
   buffer.concat x 6.72 ops/sec ±21.71% (24 runs sampled)
   Array.push x 47.35 ops/sec ±1.56% (61 runs sampled)
   Fastest is Array.push
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@thrift.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to