buffer-to-string.js 568 B

12345678910111213141516171819202122232425
  1. var a = new Buffer(10000);
  2. a.fill(120); // 'x'
  3. var l = 5;
  4. var s = '';
  5. var repeats = 10000;
  6. module.exports = function(next) {
  7. for (var n=0; n < repeats; ++n) {
  8. for (var i=0; i < a.length - l; ++i) {
  9. s = s.toString('utf8', i, i+l);
  10. }
  11. }
  12. next();
  13. };
  14. module.exports.comment = 'read ' + l + ' chars strings from ' + a.length + ' bytes buffer x ' + repeats;
  15. module.exports.toSpeed = function(time, timeError) {
  16. var value = 1e9*a.length*l*repeats / time;
  17. return {
  18. value: value,
  19. error: value*(timeError/time),
  20. units: 'chars/second'
  21. };
  22. };