Skip to content

Commit

Permalink
parser optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Llamas committed Jul 24, 2013
1 parent 9e0c160 commit 52584d0
Show file tree
Hide file tree
Showing 17 changed files with 621 additions and 456 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
10 changes: 6 additions & 4 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
v1.0.0 (xx Jul 2013)
Complete refactor.
This new version only iterates the data one time, while the previous version
was a direct port from the Java source code and was iterating four times
over the same data.
Improved speed by ~37%. This new version only iterates the data one time,
while the previous version was a direct port from the Java source code and
was iterating four times over the same data.
All the dependencies have been removed.
"load()" and "store" have been removed and "parse()" and "stringify()" can
read and write to files with the "path" setting.
Added "json" parameter. When it is enabled stringified json arrays and objects
are parsed.
are parsed into javascript arrays and objects.
Removed "bufferSize" and "encoding" parameters. Files are read using a 16KB
buffer size and utf8 encoding.
Fixed some unusual bugs with escaped backslashes.
Expand Down
2 changes: 2 additions & 0 deletions MIGRATION-v0.3-v1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Se elimina "load()" y "store()" y "parse()" y "stringify()" leen o escriben
a archivo usando el parámetro "path".
8 changes: 4 additions & 4 deletions bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ speedy.run ({
pOld.parse (data, { sections: true });
},
"new": function (){
pNew.parse (data, { data: true, sections: true }, function (){});
pNew.parse (data, { sections: true });
}
});

Expand All @@ -32,9 +32,9 @@ Total time: ~6000ms (6s 0ms)
Higher is better (ops/sec)
old
11,980 ± 0.2%
11,132 ± 0.0%
new
12,130 ± 0.4%
17,670 ± 0.2%
Elapsed time: 6112ms (6s 112ms)
Elapsed time: 6131ms (6s 131ms)
*/
42 changes: 42 additions & 0 deletions benchmark/ini-vs-properties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"use strict";

var speedy = require ("speedy");
var fs = require ("fs");
var ini = require ("ini");
var properties = require ("../lib");

var data = fs.readFileSync ("properties", { encoding: "utf8" });

speedy.run ({
ini: function (){
ini.parse (data);
},
properties: function (){
properties.parse (data, { sections: true });
}
});

//Note: ini doesn't convert the values to numbers

/*
File: ini-vs-properties.js
Node v0.10.13
V8 v3.14.5.9
Speedy v0.0.8
Benchmarks: 2
Timeout: 1000ms (1s 0ms)
Samples: 3
Total time per benchmark: ~3000ms (3s 0ms)
Total time: ~6000ms (6s 0ms)
Higher is better (ops/sec)
ini
24,815 ± 0.3%
properties
22,449 ± 0.2%
Elapsed time: 6140ms (6s 140ms)
*/
27 changes: 27 additions & 0 deletions benchmark/json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"strings": {
"s1": "v",
"s2": "v",
"s3": "v",
"s4": "v",
"s5": "v"
},
"numbers": {
"n1": 1,
"n2": 1,
"n3": 1,
"n4": 123.123,
"n5": 123.123,
"n6": 123.123
},
"arrays": {
"a1": ["1", 1, 123.123]
},
"objects": {
"o1": {
"a": "1",
"b": 1,
"c": 123.123
}
}
}
42 changes: 42 additions & 0 deletions benchmark/json-vs-properties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"use strict";

var speedy = require ("speedy");
var properties = require ("../lib");
var fs = require ("fs");

var jsonData = fs.readFileSync ("json", { encoding: "utf8" });
var propertiesData = fs.readFileSync ("properties", { encoding: "utf8" });

speedy.run ({
json: function (){
JSON.parse (jsonData);
},
properties: function (){
properties.parse (propertiesData, { sections: true, json: true });
}
});

//Note: JSON.parse is written in native by the people that made the V8 engine!

/*
File: json-vs-properties.js
Node v0.10.13
V8 v3.14.5.9
Speedy v0.0.8
Benchmarks: 2
Timeout: 1000ms (1s 0ms)
Samples: 3
Total time per benchmark: ~3000ms (3s 0ms)
Total time: ~6000ms (6s 0ms)
Higher is better (ops/sec)
json
374,519 ± 0.0%
properties
21,360 ± 0.2%
Elapsed time: 6131ms (6s 131ms)
*/
24 changes: 24 additions & 0 deletions benchmark/properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[strings]
s1 = v
s2 = v
s3 = v
s4 = v
s5 = v

[numbers]
n1 = 1
n2 = 1
n3 = 1
n4 = 123.123
n5 = 123.123
n6 = 123.123

[arrays]
a1 = ["1", 1, 123.123]
a2 = ["1", 1, 123.123]
a3 = ["1", 1, 123.123]

[objects]
o1 = { "a": "1", "b": 1, "c": 123.123 }
o2 = { "a": "1", "b": 1, "c": 123.123 }
o3 = { "a": "1", "b": 1, "c": 123.123 }
6 changes: 4 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"use strict";

module.exports.parse = require ("./parse");
module.exports.stringify = require ("./stringify");
module.exports = {
parse: require ("./read"),
stringify: require ("./write")
};
Loading

0 comments on commit 52584d0

Please sign in to comment.