Skip to content

Commit

Permalink
add JS benchmark: storage
Browse files Browse the repository at this point in the history
  • Loading branch information
IR0NSIGHT committed Jan 15, 2024
1 parent 8f30eb3 commit b48f907
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/javascript/Storage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// @ts-check
// This code is derived from the SOM benchmarks, see AUTHORS.md file.
//
// Copyright (c) 2015-2016 Stefan Marr <[email protected]>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the 'Software'), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

const { runFromCli } = require('./cliRunner');
const { Random } = require('./som');

class Storage {
constructor() {
this.count = 0;
}

benchmark() {
const random = new Random();
this.count = 0;
this.buildTreeDepth(7, random);
return this.count;
}

verifyResult(result) {
return 5461 === result;
}

buildTreeDepth(depth, random) {
this.count += 1;
if (depth === 1) {
return new Array((random.next() % 10) + 1);
}
const arr = new Array(4);
for (let i = 0; i < 4; i += 1) {
arr[i] = this.buildTreeDepth(depth - 1, random);
}
return arr;
}
}


const miniRun = () => {
new Storage().benchmark()
}

const normalRun = () => {
new Storage().benchmark()
}

const main = () => {
console.log(runFromCli(miniRun, normalRun))
}
main()

0 comments on commit b48f907

Please sign in to comment.