Skip to content

Instantly share code, notes, and snippets.

@nkallen
Last active December 22, 2015 02:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkallen/6406128 to your computer and use it in GitHub Desktop.
Save nkallen/6406128 to your computer and use it in GitHub Desktop.
Performance for loading a blob at a particular commit and accessing some of its immutable fields. Benchmark A access its fields and crosses the runtime boundary for each field access. Benchmark B does not access any fields and thus doesn't cross the runtime boundary as often (to be precise, 7 times versus 4 times). As you can see, performance is…
var git = require('../'),
path = require('path');
// This example opens a certain file, `README.md`, at a particular commit,
// and prints the first 10 lines as well as some metadata.
function doIt(cb) {
git.Repo.open(path.resolve(__dirname, '../.git'), function(error, repo) {
if (error) throw error;
repo.getCommit('59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5', function(error, commit) {
if (error) throw error;
commit.getEntry('README.md', function(error, entry) {
if (error) throw error;
entry.getBlob(function(error, blob) {
if (error) throw error;
cb([entry.name(), entry.sha(), blob.size()]); // crosses the runtime barrier 3 times.
});
});
});
});
}
function repeat(i, f, next) {
if (i == 0) return next();
f(function() { repeat(i - 1, f, next) })
}
var warmup = 100,
num = 2000;
repeat(warmup, doIt, function() {
var start = new Date().getTime();
repeat(num, doIt, function() {
var end = new Date().getTime();
console.log('Completed ' + num + ' operations, at ' + ((end - start) / num).toString() + 'ms per operation');
})
});
// Completed 2000 operations, at 0.64ms per operation
// Completed 2000 operations, at 0.6435ms per operation
// Completed 2000 operations, at 0.638ms per operation
// Completed 2000 operations, at 0.6505ms per operation
var git = require('../'),
path = require('path');
// This example opens a certain file, `README.md`, at a particular commit,
// and prints the first 10 lines as well as some metadata.
function doIt(cb) {
git.Repo.open(path.resolve(__dirname, '../.git'), function(error, repo) {
if (error) throw error;
repo.getCommit('59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5', function(error, commit) {
if (error) throw error;
commit.getEntry('README.md', function(error, entry) {
if (error) throw error;
entry.getBlob(function(error, blob) {
if (error) throw error;
cb() //[entry.name(), entry.sha(), blob.size()]); // crosses the runtime barrier 3 times.
});
});
});
});
}
function repeat(i, f, next) {
if (i == 0) return next();
f(function() { repeat(i - 1, f, next) })
}
var warmup = 100,
num = 2000;
repeat(warmup, doIt, function() {
var start = new Date().getTime();
repeat(num, doIt, function() {
var end = new Date().getTime();
console.log('Completed ' + num + ' operations, at ' + ((end - start) / num).toString() + 'ms per operation');
})
});
// Completed 2000 operations, at 0.639ms per operation
// Completed 2000 operations, at 0.6315ms per operation
// Completed 2000 operations, at 0.63ms per operation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment