From 3a6fbeee3bec15366788df7388c87586c0875bbc Mon Sep 17 00:00:00 2001 From: Matt Walsh Date: Thu, 4 Nov 2021 14:23:30 -0500 Subject: [PATCH] add benchmarking --- .vscode/launch.json | 9 +++++++++ demos/benchmark.js | 48 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 demos/benchmark.js diff --git a/.vscode/launch.json b/.vscode/launch.json index 8349736..ab73d23 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,6 +12,15 @@ "/**" ], "program": "${workspaceFolder}/demos/test.js" + }, + { + "type": "pwa-node", + "request": "launch", + "name": "Benchmark", + "skipFiles": [ + "/**" + ], + "program": "${workspaceFolder}/demos/benchmark.js" } ] } \ No newline at end of file diff --git a/demos/benchmark.js b/demos/benchmark.js new file mode 100644 index 0000000..f95f0b6 --- /dev/null +++ b/demos/benchmark.js @@ -0,0 +1,48 @@ +const { Level2Radar } = require('nexrad-level-2-data'); +// eslint-disable-next-line import/no-extraneous-dependencies +const glob = require('glob'); +const fs = require('fs'); + +const { plot, writePngToFile } = require('../src'); + +// list files +const files = glob.sync('./data/KLOT/KLOT20210812_171451_V*'); // ref palette tuning + +// const store each file's data +const chunks = []; + +// parse each file +files.forEach((file) => { + const fileBuffer = fs.readFileSync(file); + chunks.push(new Level2Radar(fileBuffer)); +}); + +// combine data +const radarData = Level2Radar.combineData(chunks); + +// result array by elevations +const plots = []; + +const size = 1800; +const elevation = 1; + +// plot for each elevation and size +(async () => { + const start = new Date(); + for (let i = 0; i < 500; i += 1) { + plots[elevation] = plot(radarData, ['REF', 'VEL'], { + elevation, + size, + palettize: true, + cropTo: size / 2, + }); + + // write files to disk + await Promise.allSettled([ + writePngToFile(`./output/REF-${elevation}-${size}--${i}.png`, plots[elevation].REF), + writePngToFile(`./output/VEL-${elevation}-${size}--${i}.png`, plots[elevation].VEL), + ]); + } + const end = new Date(); + console.log(`Total Time: ${(end - start) / 1000}`); +})();