Skip to content

Instantly share code, notes, and snippets.

@kenany
Last active December 21, 2015 23:48
Show Gist options
  • Save kenany/6384447 to your computer and use it in GitHub Desktop.
Save kenany/6384447 to your computer and use it in GitHub Desktop.
toml for node benchmarks
var fs = require('fs');
var museToml = require('toml');
var alexToml = require('toml-js');
// redhotvengeance/topl doesn't support 0.1
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite;
suite
.add('BinaryMuse/toml-node', function() {
var parsed = museToml.parse(bench);
})
.add('alexanderbeletsky/toml-js', function() {
var parsed = alexToml.parse(bench);
})
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('complete', function() {
console.log('\nFastest is ' + this.filter('fastest').pluck('name'));
});
var bench;
fs.readFile('./bench.toml', function(error, data) {
if (error) throw error;
bench = data;
suite.run({'async': true});
});
# This is a TOML document. Boom.
title = "TOML Example"
[owner]
name = "Tom Preston-Werner"
organization = "GitHub"
bio = "GitHub Cofounder & CEO\nLikes tater tots and beer."
dob = 1979-05-27T07:32:00Z # First class dates? Why not?
[database]
server = "192.168.1.1"
ports = [ 8001, 8001, 8002 ]
connection_max = 5000
enabled = true
[servers]
# You can indent as you please. Tabs or spaces. TOML don't care.
[servers.alpha]
ip = "10.0.0.1"
dc = "eqdc10"
[servers.beta]
ip = "10.0.0.2"
dc = "eqdc10"
[clients]
data = [ ["gamma", "delta"], [1, 2] ] # just an update to make sure parsers support it
# Line breaks are OK when inside arrays
hosts = [
"alpha",
"omega"
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment