diff --git a/Gruntfile.js b/Gruntfile.js index bbd9fdc..02237c2 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -4,10 +4,21 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-execute'); grunt.loadNpmTasks('grunt-contrib-clean'); + grunt.loadNpmTasks('grunt-benchmark'); grunt.initConfig({ - clean: ["dist"], + clean: { + dist: { + src: ["dist"] + }, + test: { + src: ["dist/test"] + }, + tmp: { + src: ["tmp"] + } + }, copy: { src_to_dist: { @@ -40,7 +51,7 @@ module.exports = function(grunt) { babel: { options: { - presets: ["es2015"] + presets: ["es2015"] }, dist: { options: { @@ -74,7 +85,15 @@ module.exports = function(grunt) { src: ['**/*.js'], dest: 'dist/test/specs' }] - } + }, + distBenchmarks: { + files: [{ + cwd: 'src/datasource-zabbix/benchmarks', + expand: true, + src: ['**/*.js'], + dest: 'dist/test/benchmarks' + }] + }, }, mochaTest: { @@ -122,12 +141,22 @@ module.exports = function(grunt) { options: { config: ".jscs.json", }, + }, + + benchmark: { + options: { + displayResults: true + }, + timeseriesBench: { + src: ['dist/test/datasource-zabbix/benchmarks/*.js'], + dest: 'tmp/benchmark.csv' + } } }); grunt.registerTask('default', [ - 'clean', + 'clean:dist', 'sass', 'copy:src_to_dist', 'copy:pluginDef', @@ -138,7 +167,7 @@ module.exports = function(grunt) { ]); grunt.registerTask('watchTask', [ - 'clean', + 'clean:dist', 'sass', 'copy:src_to_dist', 'copy:pluginDef', @@ -146,4 +175,12 @@ module.exports = function(grunt) { 'jshint', 'jscs' ]); + + grunt.registerTask('bench', [ + 'clean:test', + 'clean:tmp', + 'babel:distTestNoSystemJs', + 'babel:distTestsSpecsNoSystemJs', + 'benchmark' + ]); }; diff --git a/dist/datasource-zabbix/benchmarks/timeseries_bench.js b/dist/datasource-zabbix/benchmarks/timeseries_bench.js new file mode 100644 index 0000000..e678a2e --- /dev/null +++ b/dist/datasource-zabbix/benchmarks/timeseries_bench.js @@ -0,0 +1,12 @@ +import ts from '../timeseries'; + +let datapoints = [[]]; + +var fibonacci = function (n) { + return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2); +}; + +module.exports = function () { + fibonacci(10); + fibonacci(8); +}; diff --git a/dist/test/datasource-zabbix/benchmarks/timeseries_bench.js b/dist/test/datasource-zabbix/benchmarks/timeseries_bench.js new file mode 100644 index 0000000..5cd69b7 --- /dev/null +++ b/dist/test/datasource-zabbix/benchmarks/timeseries_bench.js @@ -0,0 +1,40 @@ +'use strict'; + +var _lodash = require('lodash'); + +var _lodash2 = _interopRequireDefault(_lodash); + +var _timeseries = require('../timeseries'); + +var _timeseries2 = _interopRequireDefault(_timeseries); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +var datapoints = [[10.7104, 1498409636085], [10.578, 1498409651011], [10.5985, 1498409666628], [10.6877, 1498409681525], [10.5495, 1498409696586], [10.5981, 1498409711009], [10.5076, 1498409726949], [11.4807, 1498409741853], [11.6165, 1498409756165], [11.8575, 1498409771018], [11.9936, 1498409786056], [10.7566, 1498409801942], [10.7484, 1498409816010], [10.6038, 1498409831018], [10.2932, 1498409846010], [10.4912, 1498409861946], [10.4151, 1498409876871], [10.2401, 1498409891710], [10.4921, 1498409906143], [10.4413, 1498409921477], [10.6318, 1498409936147], [10.5277, 1498409951915], [10.6333, 1498409966052], [10.6417, 1498409981944], [10.4505, 1498409996867], [10.5812, 1498410011770], [10.4934, 1498410026573], [10.5731, 1498410041317], [10.5, 1498410056213], [10.6505, 1498410071013], [9.4035, 1498410086387]]; + +var series_set = [[[1.0247, 1498409631773], [0.9988, 1498409646697], [0.9817, 1498409661239], [0.9569, 1498409676045], [1.0331, 1498409691922], [1.0755, 1498409706546], [1.1862, 1498409721525], [1.2984, 1498409736175], [1.2389, 1498409751817], [1.1452, 1498409766783], [1.102, 1498409781699], [0.9647, 1498409796664], [1.0063, 1498409811627], [1.0318, 1498409826887], [1.065, 1498409841645], [1.0907, 1498409856647], [1.0229, 1498409871521], [1.0654, 1498409886031], [1.0568, 1498409901544], [1.0818, 1498409916194], [1.1335, 1498409931672], [1.057, 1498409946673], [1.0243, 1498409961669], [1.0329, 1498409976637], [1.1428, 1498409991563], [1.2198, 1498410006441], [1.2192, 1498410021230], [1.2615, 1498410036027], [1.1765, 1498410051907], [1.2352, 1498410066109], [1.0557, 1498410081043]], [[10.7104, 1498409636085], [10.578, 1498409651011], [10.5985, 1498409666628], [10.6877, 1498409681525], [10.5495, 1498409696586], [10.5981, 1498409711009], [10.5076, 1498409726949], [11.4807, 1498409741853], [11.6165, 1498409756165], [11.8575, 1498409771018], [11.9936, 1498409786056], [10.7566, 1498409801942], [10.7484, 1498409816010], [10.6038, 1498409831018], [10.2932, 1498409846010], [10.4912, 1498409861946], [10.4151, 1498409876871], [10.2401, 1498409891710], [10.4921, 1498409906143], [10.4413, 1498409921477], [10.6318, 1498409936147], [10.5277, 1498409951915], [10.6333, 1498409966052], [10.6417, 1498409981944], [10.4505, 1498409996867], [10.5812, 1498410011770], [10.4934, 1498410026573], [10.5731, 1498410041317], [10.5, 1498410056213], [10.6505, 1498410071013], [9.4035, 1498410086387]]]; + +module.exports = [{ + name: 'groupBy', + tests: { + 'groupBy(AVERAGE)': function groupByAVERAGE() { + _timeseries2.default.groupBy(datapoints, '5m', _timeseries2.default.AVERAGE); + }, + 'groupBy(MAX)': function groupByMAX() { + _timeseries2.default.groupBy(datapoints, '5m', _timeseries2.default.COUNT); + } + } +}, { + name: 'sumSeries', + tests: { + 'sumSeries()': function sumSeries() { + _timeseries2.default.sumSeries(series_set); + }, + 'groupBy(MAX)->sumSeries()': function groupByMAXSumSeries() { + var prepeared_series = _lodash2.default.map(series_set, function (datapoints) { + return _timeseries2.default.groupBy(datapoints, '5m', _timeseries2.default.MAX); + }); + _timeseries2.default.sumSeries(prepeared_series); + } + } +}]; diff --git a/package.json b/package.json index 93d8731..4edc740 100644 --- a/package.json +++ b/package.json @@ -20,9 +20,11 @@ "babel-plugin-transform-es2015-for-of": "^6.6.0", "babel-plugin-transform-es2015-modules-systemjs": "^6.5.0", "babel-preset-es2015": "^6.5.0", + "benchmark":"^2.1.4", "chai": "~3.5.0", "grunt": "~0.4.5", "grunt-babel": "~6.0.0", + "grunt-benchmark": "^1.0.0", "grunt-contrib-clean": "~0.6.0", "grunt-contrib-copy": "~0.8.2", "grunt-contrib-jshint": "^1.0.0", diff --git a/src/datasource-zabbix/benchmarks/timeseries_bench.js b/src/datasource-zabbix/benchmarks/timeseries_bench.js new file mode 100644 index 0000000..845b54f --- /dev/null +++ b/src/datasource-zabbix/benchmarks/timeseries_bench.js @@ -0,0 +1,35 @@ +import _ from 'lodash'; +import ts from '../timeseries'; + +let datapoints = [[10.7104, 1498409636085], [10.578, 1498409651011], [10.5985, 1498409666628], [10.6877, 1498409681525], [10.5495, 1498409696586], [10.5981, 1498409711009], [10.5076, 1498409726949], [11.4807, 1498409741853], [11.6165, 1498409756165], [11.8575, 1498409771018], [11.9936, 1498409786056], [10.7566, 1498409801942], [10.7484, 1498409816010], [10.6038, 1498409831018], [10.2932, 1498409846010], [10.4912, 1498409861946], [10.4151, 1498409876871], [10.2401, 1498409891710], [10.4921, 1498409906143], [10.4413, 1498409921477], [10.6318, 1498409936147], [10.5277, 1498409951915], [10.6333, 1498409966052], [10.6417, 1498409981944], [10.4505, 1498409996867], [10.5812, 1498410011770], [10.4934, 1498410026573], [10.5731, 1498410041317], [10.5, 1498410056213], [10.6505, 1498410071013], [9.4035, 1498410086387]]; + +let series_set = [ + [[1.0247, 1498409631773], [0.9988, 1498409646697], [0.9817, 1498409661239], [0.9569, 1498409676045], [1.0331, 1498409691922], [1.0755, 1498409706546], [1.1862, 1498409721525], [1.2984, 1498409736175], [1.2389, 1498409751817], [1.1452, 1498409766783], [1.102, 1498409781699], [0.9647, 1498409796664], [1.0063, 1498409811627], [1.0318, 1498409826887], [1.065, 1498409841645], [1.0907, 1498409856647], [1.0229, 1498409871521], [1.0654, 1498409886031], [1.0568, 1498409901544], [1.0818, 1498409916194], [1.1335, 1498409931672], [1.057, 1498409946673], [1.0243, 1498409961669], [1.0329, 1498409976637], [1.1428, 1498409991563], [1.2198, 1498410006441], [1.2192, 1498410021230], [1.2615, 1498410036027], [1.1765, 1498410051907], [1.2352, 1498410066109], [1.0557, 1498410081043]], + [[10.7104, 1498409636085], [10.578, 1498409651011], [10.5985, 1498409666628], [10.6877, 1498409681525], [10.5495, 1498409696586], [10.5981, 1498409711009], [10.5076, 1498409726949], [11.4807, 1498409741853], [11.6165, 1498409756165], [11.8575, 1498409771018], [11.9936, 1498409786056], [10.7566, 1498409801942], [10.7484, 1498409816010], [10.6038, 1498409831018], [10.2932, 1498409846010], [10.4912, 1498409861946], [10.4151, 1498409876871], [10.2401, 1498409891710], [10.4921, 1498409906143], [10.4413, 1498409921477], [10.6318, 1498409936147], [10.5277, 1498409951915], [10.6333, 1498409966052], [10.6417, 1498409981944], [10.4505, 1498409996867], [10.5812, 1498410011770], [10.4934, 1498410026573], [10.5731, 1498410041317], [10.5, 1498410056213], [10.6505, 1498410071013], [9.4035, 1498410086387]] +]; + +module.exports = [ + { + name: 'groupBy', + tests: { + 'groupBy(AVERAGE)': () => { + ts.groupBy(datapoints, '5m', ts.AVERAGE); + }, + 'groupBy(MAX)': () => { + ts.groupBy(datapoints, '5m', ts.COUNT); + } + } + }, + { + name: 'sumSeries', + tests: { + 'sumSeries()': () => { + ts.sumSeries(series_set); + }, + 'groupBy(MAX)->sumSeries()': () => { + let prepeared_series = _.map(series_set, datapoints => ts.groupBy(datapoints, '5m', ts.MAX)); + ts.sumSeries(prepeared_series); + } + } + } +];