This file is indexed.

/usr/share/doc/node-node-redis/examples/bench.js is in node-node-redis 0.1.7-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
var redis  = require('./lib/node-redis'),
    //redis2 = require('redis'),
    //redis3 = require('./bench/redis-node/redis'),
    //redis4 = require('./bench/redis-client'),
    Seq    = require('parallel').Sequence,
    assert = require('assert');

var clients = { 'node-redis': redis.createClient()/*,  'node_redis':        redis2.createClient(),*/
                /*'redis-node': redis3.createClient(), 'redis-node-client': redis4.createClient()*/ }

var iterations = 5000,
    number     = 5;

//var buffer = JSON.stringify({
  //name: 'Bob Marley',
  //dob: '31/12/1980',
  //hash: '213897d9827o7fn437nv348n534',
  //salt: '12345',
  //bio: 'p983u4f hh sdh khfkslh kfjh dkshljdh k hslhlhuil huihsuidh liushuilsh lihgudif hlugfdhliughduil hgdf',
  //created: Date.now()
//});
//var buffer = require('fs').readFileSync('binary');
//var buffer = new Buffer(Array(1025 * 2).join('x'));
//var buffer = Array(1025 * 2).join('x');
var buffer = 'Some some random text for the benchmark.';
//var buffer = 'xxx';
//var buffer = require('fs').readFileSync('bench/html');

var benches = {
  set: function (client, callback) {
    for (var i = 0; i < iterations - 1; i++) {
      client.set('bench' + i, buffer);
    }
    client.set('bench' + i, buffer, callback);
  },
  get: function (client, callback) {
    for (var i = 0; i < iterations - 1; i++) {
      client.get('bench' + i);
    }
    client.get('bench' + i, callback);
  },
  del: function (client, callback) {
    for (var i = 0; i < iterations - 1; i++) {
      client.del('bench' + i);
    }
    client.del('bench' + i, callback);
  },
  lpush: function (client, callback) {
    for (var i = 0; i < iterations - 1; i++) {
      client.lpush('bench', buffer);
    }
    client.lpush('bench', buffer, callback);
  },
  lrange: function (client, callback) {
    for (var i = 0; i < iterations - 1; i++) {
      client.lrange('bench', 0, 10);
    }
    client.lrange('bench', 0, 10, callback);
  },
  hmset: function (client, callback) {
    if ('redis-node' === client._name) return callback();
    for (var i = 0; i < iterations - 1; i++) {
      client.hmset('bench' + i, 'key', buffer, 'key2', buffer);
    }
    client.hmset('bench' + i, 'key', buffer, 'key2', buffer, callback);
  },
  hmget: function (client, callback) {
    if ('redis-node' === client._name) return callback();
    for (var i = 0; i < iterations - 1; i++) {
      client.hmget('bench' + i, 'key', 'key2');
    }
    client.hmget('bench' + i, 'key', 'key2', callback);
  },
  del2: function (client, callback) {
    for (var i = 0; i < iterations - 1; i++) {
      client.del('bench' + i);
    }
    client.del('bench' + i, callback);
  },
};

var task   = new Seq(),
    warmup = new Seq();

Object.keys(clients).forEach(function (client) {
  clients[client]._name = client;
  client                = clients[client];
  client.benches        = {};

  for (var i = 0; i < number; i++) {
    Object.keys(benches).forEach(function (bench) {
      client.benches[bench] = [];

      task.add(function (next, error) {
        process.stdout.write('.');
        var time = Date.now();
        benches[bench](client, function (error) {
          client.benches[bench].push(Date.now() - time);
          next();
        });
      });
    });

    task.add(function (next) {
      client.del('bench', next);
    });
  }
});
Object.keys(clients).forEach(function (client) {
  clients[client]._name = client;
  client                = clients[client];
  client.benches        = {};

  Object.keys(benches).forEach(function (bench) {
    client.benches[bench] = [];

    warmup.add(function (next) {
      client.flushall(next);
    });
  });
});

clients['node-redis'].on('connect', function () {
  var old_iter = iterations;

  iterations = 100;

  warmup.run(function () {
    //throw new Error;
    iterations = old_iter;
    setTimeout(function () {
      task.run(end);
    }, 1000);
  });
});

var end = function end () {
  process.stdout.write('\r\n');
  var bench, client_name, client,
      keys       = Object.keys(clients),
      bench_keys = Object.keys(benches);

  for (var i = 0, il = bench_keys.length; i < il; i++) {
    bench = bench_keys[i];
    console.log('=== ' + bench + ' x' + iterations + ' ===');

    for (var j = 0, jl = keys.length; j < jl; j++) {
      client_name = keys[j];
      client      = clients[client_name];

      console.log(client_name + ' results: ' + client.benches[bench].join(', '));
    }

    console.log('');

    for (j = 0, jl = keys.length; j < jl; j++) {
      client_name = keys[j];
      client      = clients[client_name];

      client.benches[bench] = eval(client.benches[bench].join('+')) / client.benches[bench].length;

      console.log(client_name + ' avg: ' + client.benches[bench]);
    }

    console.log('');

    for (j = 0, jl = keys.length; j < jl; j++) {
      client_name = keys[j];
      client      = clients[client_name];

      console.log(client_name + ' ops/s: ' + ((iterations / client.benches[bench]) * 1000));
    }

    console.log('\r\n');
  }

  // Bye!
  process.exit();
};