<commit_before>var Benchmark = require('benchmark'),
    suite = new Benchmark.Suite();
var CXXCache = require('../lib/util/cxxcache');
var fs = require('fs');

function getter(term,shard,ext) {
    return fs.readFileSync(__dirname + '/fixtures/' + term+'-'+shard+ext);
}

var bench = new Benchmark('CXXCache Term',{
    'defer':true,
    'fn': function(deferred) {
        var cache = new CXXCache('a', 2);
        [['term',0],['term',1],['term',2]].forEach(function(msg) {
            cache.loadSync(getter(msg[0],msg[1],'.pbf'), msg[0],msg[1]);
        });
        deferred.resolve();        
    }
});
suite.add(bench)

var bench = new Benchmark('CXXCache Phrase',{
    'defer':true,
    'fn': function(deferred) {
        var cache = new CXXCache('a', 2);
        [['phrase',0],['phrase',2]].forEach(function(msg) {
            cache.loadSync(getter(msg[0],msg[1],'.pbf'), msg[0],msg[1]);
        });
        deferred.resolve();        
    }
});
suite.add(bench)

suite.on('cycle', function(event) {
  console.log(String(event.target));
})

suite.on('complete', function() {
  console.log('Fastest is ' + this.filter('fastest').pluck('name'));
})

suite.run();<commit_msg>simplify async benchmark syntax as per https://github.com/bestiejs/benchmark.js/pull/56<commit_after>var Benchmark = require('benchmark'),
    suite = new Benchmark.Suite();
var CXXCache = require('../lib/util/cxxcache');
var fs = require('fs');

function getter(term,shard,ext) {
    return fs.readFileSync(__dirname + '/fixtures/' + term+'-'+shard+ext);
}

suite.add('CXXCache Term',{
    'defer':true,
    'fn': function(deferred) {
        var cache = new CXXCache('a', 2);
        [['term',0],['term',1],['term',2]].forEach(function(msg) {
            cache.loadSync(getter(msg[0],msg[1],'.pbf'), msg[0],msg[1]);
        });
        deferred.resolve();        
    }
});

suite.add('CXXCache Phrase',{
    'defer':true,
    'fn': function(deferred) {
        var cache = new CXXCache('a', 2);
        [['phrase',0],['phrase',2]].forEach(function(msg) {
            cache.loadSync(getter(msg[0],msg[1],'.pbf'), msg[0],msg[1]);
        });
        deferred.resolve();        
    }
});

suite.on('cycle', function(event) {
  console.log(String(event.target));
})

suite.on('complete', function() {
  console.log('Fastest is ' + this.filter('fastest').pluck('name'));
})

suite.run();
{'fraction_non_alphanumeric': 0.2203891708967851, 'fraction_numerical': 0.01353637901861252, 'mean_word_length': 3.4371482176360226, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6930221', 'n_tokens_mistral': 838, 'n_tokens_neox': 824, 'n_words': 123}