-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add benchmarking support to swingset-runner
- Loading branch information
Showing
7 changed files
with
318 additions
and
19 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
packages/swingset-runner/demo/pingPongBenchmark/bootstrap.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import harden from '@agoric/harden'; | ||
|
||
console.log(`=> loading bootstrap.js`); | ||
|
||
export default function setup(syscall, state, helpers) { | ||
function log(what) { | ||
helpers.log(what); | ||
console.log(what); | ||
} | ||
log(`=> setup called`); | ||
let alice; | ||
let bob; | ||
return helpers.makeLiveSlots( | ||
syscall, | ||
state, | ||
E => | ||
harden({ | ||
bootstrap(argv, vats) { | ||
alice = vats.alice; | ||
bob = vats.bob; | ||
console.log('=> bootstrap() called'); | ||
E(alice).setNickname('alice'); | ||
E(bob).setNickname('bob'); | ||
E(alice) | ||
.introduceYourselfTo(bob) | ||
.then( | ||
r => log(`=> alice.introduceYourselfTo(bob) resolved to '${r}'`), | ||
e => log(`=> alice.introduceYourselfTo(bob) rejected as '${e}'`), | ||
); | ||
}, | ||
runBenchmarkRound() { | ||
E(alice).doPing('hey!'); | ||
}, | ||
}), | ||
helpers.vatID, | ||
); | ||
} |
48 changes: 48 additions & 0 deletions
48
packages/swingset-runner/demo/pingPongBenchmark/vat-alice.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import harden from '@agoric/harden'; | ||
|
||
function build(E, log) { | ||
let myNickname; | ||
let otherNickname = 'unknown'; | ||
let otherContact = null; | ||
|
||
function makeContact() { | ||
return harden({ | ||
myNameIs(nickname) { | ||
otherNickname = nickname; | ||
log(`${myNickname}: contact is now named ${otherNickname}`); | ||
}, | ||
pong(tag, ponger) { | ||
log(`${myNickname}: ponged with "${tag}" by ${ponger}`); | ||
}, | ||
}); | ||
} | ||
|
||
return harden({ | ||
setNickname(nickname) { | ||
myNickname = nickname; | ||
}, | ||
introduceYourselfTo(other) { | ||
log(`${myNickname}.introduce`); | ||
const myContact = makeContact(); | ||
otherContact = E(other).hello(myContact, myNickname); | ||
return `${myNickname} setup done\n${myNickname} vat is happy\n`; | ||
}, | ||
doPing(tag) { | ||
log(`${myNickname}: pings ${otherNickname} with ${tag}`); | ||
E(otherContact).ping(tag); | ||
}, | ||
}); | ||
} | ||
|
||
export default function setup(syscall, state, helpers) { | ||
function log(what) { | ||
helpers.log(what); | ||
console.log(what); | ||
} | ||
return helpers.makeLiveSlots( | ||
syscall, | ||
state, | ||
E => build(E, log), | ||
helpers.vatID, | ||
); | ||
} |
39 changes: 39 additions & 0 deletions
39
packages/swingset-runner/demo/pingPongBenchmark/vat-bob.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import harden from '@agoric/harden'; | ||
|
||
function build(E, log) { | ||
let myNickname; | ||
|
||
function makeContact(otherContact, otherNickname) { | ||
return harden({ | ||
ping(tag) { | ||
log(`${myNickname}: pinged with "${tag}", ponging ${otherNickname}`); | ||
E(otherContact).pong(tag, myNickname); | ||
}, | ||
}); | ||
} | ||
|
||
return harden({ | ||
setNickname(nickname) { | ||
myNickname = nickname; | ||
}, | ||
hello(otherContact, otherNickname) { | ||
const myContact = makeContact(otherContact, otherNickname); | ||
E(otherContact).myNameIs(myNickname); | ||
log(`${myNickname}.hello sees ${otherNickname}`); | ||
return myContact; | ||
}, | ||
}); | ||
} | ||
|
||
export default function setup(syscall, state, helpers) { | ||
function log(what) { | ||
helpers.log(what); | ||
console.log(what); | ||
} | ||
return helpers.makeLiveSlots( | ||
syscall, | ||
state, | ||
E => build(E, log), | ||
helpers.vatID, | ||
); | ||
} |
44 changes: 44 additions & 0 deletions
44
packages/swingset-runner/demo/promiseChainBenchmark/bootstrap.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import harden from '@agoric/harden'; | ||
|
||
console.log(`=> loading bootstrap.js`); | ||
|
||
function build(E, log) { | ||
let bob; | ||
let p; | ||
function waitForNextResolution() { | ||
p.then( | ||
answer => { | ||
log(`Alice: Bob answers with value ${answer[0]}`); | ||
p = answer[1]; | ||
E(bob).gen(); | ||
}, | ||
err => { | ||
log(`=> Alice: Bob rejected, ${err}`); | ||
}, | ||
); | ||
} | ||
|
||
return { | ||
bootstrap(argv, vats) { | ||
bob = vats.bob; | ||
p = E(bob).init(); | ||
E(bob).gen(); | ||
}, | ||
runBenchmarkRound() { | ||
waitForNextResolution(); | ||
}, | ||
}; | ||
} | ||
|
||
export default function setup(syscall, state, helpers) { | ||
function log(what) { | ||
helpers.log(what); | ||
console.log(what); | ||
} | ||
return helpers.makeLiveSlots( | ||
syscall, | ||
state, | ||
E => harden(build(E, log)), | ||
helpers.vatID, | ||
); | ||
} |
43 changes: 43 additions & 0 deletions
43
packages/swingset-runner/demo/promiseChainBenchmark/vat-bob.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import harden from '@agoric/harden'; | ||
|
||
function makePR() { | ||
let r; | ||
const p = new Promise((resolve, _reject) => { | ||
r = resolve; | ||
}); | ||
return [p, r]; | ||
} | ||
|
||
function build(_E, _log) { | ||
let r = null; | ||
let value = 0; | ||
return { | ||
init() { | ||
let p; | ||
// eslint-disable-next-line prefer-const | ||
[p, r] = makePR(); | ||
return p; | ||
}, | ||
gen() { | ||
// eslint-disable-next-line prefer-const | ||
let [p, newR] = makePR(); | ||
const answer = [value, p]; | ||
value += 1; | ||
r(answer); | ||
r = newR; | ||
}, | ||
}; | ||
} | ||
|
||
export default function setup(syscall, state, helpers) { | ||
function log(what) { | ||
helpers.log(what); | ||
console.log(what); | ||
} | ||
return helpers.makeLiveSlots( | ||
syscall, | ||
state, | ||
E => harden(build(E, log)), | ||
helpers.vatID, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.