~ubuntu-branches/ubuntu/saucy/nodejs/saucy-proposed

« back to all changes in this revision

Viewing changes to benchmark/fs/readfile.js

  • Committer: Package Import Robot
  • Author(s): Jérémy Lal
  • Date: 2013-08-14 00:16:46 UTC
  • mfrom: (7.1.40 sid)
  • Revision ID: package-import@ubuntu.com-20130814001646-bzlysfh8sd6mukbo
Tags: 0.10.15~dfsg1-4
* Update 2005 patch, adding a handful of tests that can fail on
  slow platforms.
* Add 1004 patch to fix test failures when writing NaN to buffer
  on mipsel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Call fs.readFile over and over again really fast.
 
2
// Then see how many times it got called.
 
3
// Yes, this is a silly benchmark.  Most benchmarks are silly.
 
4
 
 
5
var path = require('path');
 
6
var common = require('../common.js');
 
7
var filename = path.resolve(__dirname, '.removeme-benchmark-garbage');
 
8
var fs = require('fs');
 
9
 
 
10
var bench = common.createBenchmark(main, {
 
11
  dur: [5],
 
12
  len: [1024, 16 * 1024 * 1024],
 
13
  concurrent: [1, 10]
 
14
});
 
15
 
 
16
function main(conf) {
 
17
  var len = +conf.len;
 
18
  try { fs.unlinkSync(filename); } catch (e) {}
 
19
  var data = new Buffer(len);
 
20
  data.fill('x');
 
21
  fs.writeFileSync(filename, data);
 
22
  data = null;
 
23
 
 
24
  var reads = 0;
 
25
  bench.start();
 
26
  setTimeout(function() {
 
27
    bench.end(reads);
 
28
    try { fs.unlinkSync(filename); } catch (e) {}
 
29
  }, +conf.dur * 1000);
 
30
 
 
31
  function read() {
 
32
    fs.readFile(filename, afterRead);
 
33
  }
 
34
 
 
35
  function afterRead(er, data) {
 
36
    if (er)
 
37
      throw er;
 
38
 
 
39
    if (data.length !== len)
 
40
      throw new Error('wrong number of bytes returned');
 
41
 
 
42
    reads++;
 
43
    read();
 
44
  }
 
45
 
 
46
  var cur = +conf.concurrent;
 
47
  while (cur--) read();
 
48
}