Skip to content

Commit

Permalink
make analyze_benches as script
Browse files Browse the repository at this point in the history
  • Loading branch information
ermalkaleci committed Dec 7, 2021
1 parent f02c576 commit 9682e7f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
26 changes: 8 additions & 18 deletions analyze_benches.ts → analyze_benches.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
import assert from 'assert';
import fs from 'fs';
import path from 'path';

interface Bench {
name: string;
weight: number;
reads: number;
writes: number;
};

type Output = Bench & {
total_weight: number;
used_gas: number;
ratio: number;
};
#!/usr/bin/env node

const assert = require('assert');
const fs = require('fs');
const path = require('path');


const stdinBuffer = fs.readFileSync(0, 'utf-8'); // STDIN_FILENO = 0
assert(stdinBuffer);
Expand All @@ -24,13 +14,13 @@ assert(bench_path);
const bench_data = fs.readFileSync(bench_path, 'utf-8');
const bench_config = fs.readFileSync(__dirname + '/build/benches.json', 'utf-8');

const benches: Bench[] = JSON.parse(bench_data);
const benches = JSON.parse(bench_data);
const config = JSON.parse(bench_config);

const db_read = 25_000_000;
const db_write = 100_000_000;

const output: Output [] = benches
const output = benches
.map(({ name, reads, writes, weight }) => {
const used_gas = config[name]['used_gas'];
const total_weight = weight + reads * db_read + writes * db_write;
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"license": "GPL-3.0-or-later",
"scripts": {
"build": "waffle waffle.json && yarn generate-benches",
"generate-benches": "ts-node-transpile-only generate_benches.ts",
"analyze-benches": "ts-node-transpile-only analyze_benches.ts"
"generate-benches": "ts-node-transpile-only generate_benches.ts"
},
"dependencies": {
"@openzeppelin/contracts": "4.3.3",
Expand Down

0 comments on commit 9682e7f

Please sign in to comment.