Browse Source

Merge branch 'benchmarks'

v1.x
Tj Holowaychuk 14 years ago
parent
commit
1e8422674c
  1. 3
      .gitmodules
  2. 2
      Makefile
  3. 4
      Readme.md
  4. 1
      benchmarks/node-o3-canvas
  5. 66
      benchmarks/run.js

3
.gitmodules

@ -7,3 +7,6 @@
[submodule "support/jade"]
path = support/jade
url = git://github.com/visionmedia/jade.git
[submodule "benchmarks/node-o3-canvas"]
path = benchmarks/node-o3-canvas
url = https://github.com/ajaxorg/node-o3-canvas.git

2
Makefile

@ -8,6 +8,6 @@ test-server:
@node test/server.js
benchmark:
@node examples/benchmark.js
@node benchmarks/run.js
.PHONY: test test-server benchmark

4
Readme.md

@ -57,6 +57,10 @@ If not previously installed, you will want to install the [cairo graphics librar
A call to `Canvas#toBuffer()` will return a node `Buffer` instance containing all of the PNG data.
## Benchmarks
Although node-canvas is extremely now, and we have not even begun optimization yet it is already quite fast. For benchmarks vs other node canvas implementations view this [gist](https://gist.github.com/664922), or update the submodules and run `$ make benchmark` yourself.
## Contribute
Want to contribute to node-canvas? patches for features, bug fixes, documentation, examples and others are certainly welcome. Take a look at the [issue queue](https://github.com/LearnBoost/node-canvas/issues) for existing issues.

1
benchmarks/node-o3-canvas

@ -0,0 +1 @@
Subproject commit 6fa7b2316fb3b9c3165efdceb15dba24342cd343

66
examples/benchmark.js → benchmarks/run.js

@ -4,9 +4,10 @@
*/
var Canvas = require('../lib/canvas')
, canvasFactory = require('./node-o3-canvas/lib/o3-canvas')
, canvas = new Canvas(200, 200)
, largeCanvas = new Canvas(1000, 1000)
, ctx = canvas.getContext('2d');
, ctx = canvas.getContext('2d')
, o3ctx = canvasFactory(200,200,'argb');
var times = 10000;
@ -40,11 +41,17 @@ function bm(label, overrideTimes, fn) {
}
}
// node-canvas
bm('lineTo()', function(){
ctx.lineTo(0, 50);
});
bm('fillStyle=', function(){
bm('fillStyle= hex', function(){
ctx.fillStyle = '#FFCCAA';
});
bm('fillStyle= rgba()', function(){
ctx.fillStyle = 'rgba(0,255,80,1)';
});
@ -68,24 +75,53 @@ bm('toBuffer() 200x200', 50, function(){
canvas.toBuffer();
});
bm('toBuffer() 1000x1000', 50, function(){
largeCanvas.toBuffer();
bm('toBuffer().toString("base64") 200x200', 50, function(){
canvas.toBuffer().toString('base64');
});
bm('toDataURL() 200x200', 50, function(){
canvas.toDataURL();
});
bm('toDataURL() 1000x1000', 50, function(){
largeCanvas.toDataURL();
// bm('PNGStream 200x200', 50, function(done){
// var stream = canvas.createSyncPNGStream();
// stream.on('data', function(chunk){
// // whatever
// });
// stream.on('end', function(){
// done();
// });
// });
// node-o3-canvas
console.log('\n node-o3-canvas\n');
bm('o3 lineTo()', function(){
o3ctx.lineTo(0, 50);
});
bm('PNGStream 1000x1000', 50, function(done){
var stream = largeCanvas.createSyncPNGStream();
stream.on('data', function(chunk){
// whatever
});
stream.on('end', function(){
done();
});
bm('o3 fillStyle= hex', function(){
o3ctx.fillStyle = '#FFCCAA';
});
bm('o3 fillStyle= rgba()', function(){
o3ctx.fillStyle = 'rgba(0,255,80,1)';
});
bm('o3 fillRect()', function(){
o3ctx.fillRect(50, 50, 100, 100);
});
bm('o3 strokeRect()', function(){
o3ctx.strokeRect(50, 50, 100, 100);
});
bm('pngBuffer() 200x200', 50, function(){
o3ctx.pngBuffer();
});
bm('pngBuffer().toBase64() 200x200', 50, function(){
o3ctx.pngBuffer().toBase64();
});
console.log();
Loading…
Cancel
Save