summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2018-10-03 15:10:22 +0200
committerFlorian Dold <florian.dold@gmail.com>2018-10-03 15:10:22 +0200
commit3771b4d6b67b34c130f3a9a1a15f42deefdb2eda (patch)
tree851da56b2aca5da085a524996496ba9bdfa65d77 /contrib
parent361463a2ff10bd3e536e34ee816b397c23dca6f7 (diff)
downloadwallet-core-3771b4d6b67b34c130f3a9a1a15f42deefdb2eda.tar.gz
wallet-core-3771b4d6b67b34c130f3a9a1a15f42deefdb2eda.tar.bz2
wallet-core-3771b4d6b67b34c130f3a9a1a15f42deefdb2eda.zip
coinsim tweaks
Diffstat (limited to 'contrib')
-rw-r--r--contrib/coinsim.ts41
1 files changed, 31 insertions, 10 deletions
diff --git a/contrib/coinsim.ts b/contrib/coinsim.ts
index 9b8e12d2e..a4eef3e72 100644
--- a/contrib/coinsim.ts
+++ b/contrib/coinsim.ts
@@ -19,22 +19,26 @@ function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
-const denoms = [512, 256, 128, 64, 32, 16, 8, 4, 2, 1];
+const denoms = [8096, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1];
// mapping from denomination index to count
const wallet = denoms.map(() => 0);
-const trans_max = 1000;
-const trans_min = 2;
+const trans_max = 5000;
+const trans_min = 4;
-const withdraw_max = 5000;
+const withdraw_max = 10000;
const num_transactions = parseInt(process.argv[2]);
// Refresh or withdraw operations
let ops = 0;
+let ops_refresh = 0;
+let ops_withdraw = 0;
+let ops_spend = 0;
+let refresh_output = 0;
-function withdraw(amount) {
+function withdraw(amount, is_refresh) {
while (amount != 0) {
for (let i = 0; i < denoms.length; i++) {
let d = denoms[i];
@@ -42,6 +46,11 @@ function withdraw(amount) {
amount -= d;
wallet[i]++;
ops++;
+ if (!is_refresh) {
+ ops_withdraw++;
+ } else {
+ refresh_output++;
+ }
break;
}
}
@@ -62,13 +71,16 @@ function spendSmallestFirst(cost) {
wallet[k]--;
cost -= d;
ops++;
+ ops_spend++;
break;
}
// partially spend and then refresh
ops++;
+ ops_spend++;
let r = d - cost;
+ ops_refresh++;
wallet[k]--;
- withdraw(r);
+ withdraw(r, true);
cost = 0;
}
}
@@ -87,13 +99,16 @@ function spendLargestFirst(cost) {
wallet[j]--;
cost -= d;
ops++;
+ ops_spend++;
break;
}
// partially spend and then refresh
ops++;
+ ops_spend++;
let r = d - cost;
+ ops_refresh++;
wallet[j]--;
- withdraw(r);
+ withdraw(r, true);
cost = 0;
}
}
@@ -112,9 +127,11 @@ function spendHybrid(cost) {
}
// partially spend and then refresh
ops++;
+ ops_spend++;
let r = d - cost;
+ ops_refresh++;
wallet[k]--;
- withdraw(r);
+ withdraw(r, true);
cost = 0;
}
@@ -132,7 +149,7 @@ for (let i = 0; i < num_transactions; i++) {
if (balance < cost) {
// we need to withdraw
let amount = getRandomInt(cost - balance, withdraw_max);
- withdraw(amount);
+ withdraw(amount, false);
}
// check that we now have enough balance
@@ -149,4 +166,8 @@ for (let i = 0; i < num_transactions; i++) {
spendHybrid(cost);
}
-console.log(ops / num_transactions);
+console.log("total ops", ops / num_transactions);
+console.log("spend ops", ops_spend / num_transactions);
+console.log("pure withdraw ops", ops_withdraw / num_transactions);
+console.log("refresh (multi output) ops", ops_refresh / num_transactions);
+console.log("refresh output", refresh_output / ops_refresh);