Skip to content

Commit

Permalink
add sieve: js benchmark + effekt dummy
Browse files Browse the repository at this point in the history
  • Loading branch information
IR0NSIGHT committed Jan 15, 2024
1 parent ff41c92 commit 46a851d
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/effekt/benchmark/sieve.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def main() = {
println("[-1]")
}
67 changes: 67 additions & 0 deletions src/javascript/Sieve.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// @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");

class Sieve {
sieve(flags, size) {
let primeCount = 0;

for (let i = 2; i <= size; i += 1) {
if (flags[i - 1]) {
primeCount += 1;
let k = i + i;
while (k <= size) {
flags[k - 1] = false;
k += i;
}
}
}
return primeCount;
}

benchmark() {
const flags = new Array(5000);
flags.fill(true);
return this.sieve(flags, 5000);
}

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

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

const normalRun = () => {
for (let i = 0; i < 10; i++) {
new Sieve().benchmark()
}
}

const main = () => {
console.log(runFromCli(miniRun, normalRun))
}
main()
3 changes: 2 additions & 1 deletion src/javascript/compare/comparator.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const commands = [
["nbody", "src/effekt/benchmark/nbody.effekt", "node src/javascript/Nbody.js"],
['list', 'src/effekt/benchmark/list.effekt', 'node src/javascript/List.js'],
["mandelbrot", "src/effekt/benchmark/mandelbrot.effekt", "node src/javascript/Mandelbrot.js"],
["bounce","src/effekt/benchmark/bounce.effekt","node src/javascript/bounce.js"]
["bounce","src/effekt/benchmark/bounce.effekt","node src/javascript/bounce.js"],
["sieve","src/effekt/benchmark/sieve.effekt", "node src/javascript/Sieve.js"],
// Add more commands as needed

];
Expand Down

0 comments on commit 46a851d

Please sign in to comment.