1 | 'use strict';
|
2 |
|
3 | var Benchmark = require('benchmark'),
|
4 | fs = require('fs'),
|
5 | protobuf = require('protocol-buffers'),
|
6 | vt = require('./vector_tile'),
|
7 | Pbf = require('../'),
|
8 | readTile = vt.Tile.read,
|
9 | writeTile = vt.Tile.write;
|
10 |
|
11 | var Tile = protobuf(fs.readFileSync(__dirname + '/vector_tile.proto')).Tile,
|
12 | data = fs.readFileSync(__dirname + '/../test/fixtures/12665.vector.pbf'),
|
13 | suite = new Benchmark.Suite();
|
14 |
|
15 | var tile = readTile(new Pbf(data)),
|
16 | tileJSON = JSON.stringify(tile),
|
17 | tile2 = Tile.decode(data);
|
18 |
|
19 | writeTile(tile, new Pbf());
|
20 |
|
21 | suite
|
22 | .add('decode vector tile with pbf', function() {
|
23 | readTile(new Pbf(data));
|
24 | })
|
25 | .add('encode vector tile with pbf', function() {
|
26 | var pbf = new Pbf();
|
27 | writeTile(tile, pbf);
|
28 | pbf.finish();
|
29 | })
|
30 | .add('decode vector tile with protocol-buffers', function() {
|
31 | Tile.decode(data);
|
32 | })
|
33 | .add('encode vector tile with protocol-buffers', function() {
|
34 | Tile.encode(tile2);
|
35 | })
|
36 | .add('JSON.parse vector tile', function() {
|
37 | JSON.parse(tileJSON);
|
38 | })
|
39 | .add('JSON.stringify vector tile', function() {
|
40 | JSON.stringify(tile);
|
41 | })
|
42 | .on('cycle', function(event) {
|
43 | console.log(String(event.target));
|
44 | })
|
45 | .run();
|