-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #328 from uqbar-project/optimization-wollok-game
Optimization wollok game
- Loading branch information
Showing
8 changed files
with
188 additions
and
50 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -113,7 +113,8 @@ | |
"time", | ||
"timeEnd", | ||
"group", | ||
"groupEnd" | ||
"groupEnd", | ||
"table" | ||
] | ||
} | ||
], | ||
|
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,30 @@ | ||
name: Run Benchmarks | ||
|
||
on: [pull_request] | ||
|
||
jobs: | ||
run-benchmarks: | ||
if: ${{ contains(github.event.pull_request.body, '[Run benchmarks]') }} | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
- name: Read .nvmrc | ||
run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)" | ||
id: nvm | ||
- name: Use Node.js (.nvmrc) | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: "${{ steps.nvm.outputs.NVMRC }}" | ||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Run benchmarks | ||
run: npm run test:benchmarks | tail -n +7 > bench-results.txt | ||
continue-on-error: true | ||
|
||
- name: Post results to comment | ||
uses: peter-evans/commit-comment@v3 | ||
with: | ||
body-path: 'bench-results.txt' |
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
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
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
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
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
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,68 @@ | ||
import { should } from 'chai' | ||
import { resolve } from 'path' | ||
import { restore, stub } from 'sinon' | ||
import { PROGRAM_FILE_EXTENSION } from '../src' | ||
import { interpret } from '../src/interpreter/interpreter' | ||
import natives from '../src/wre/wre.natives' | ||
import { buildEnvironment } from './utils' | ||
|
||
should() | ||
|
||
describe('Benchmarks', () => { | ||
const results: any[] = [] | ||
|
||
after(() => console.table(results)) | ||
|
||
describe('flushEvents', () => { | ||
|
||
function benchmark(fqn: string, expectedTime = 0) { | ||
it(fqn, async () => { | ||
stub(console) | ||
const iterations = 30 | ||
|
||
const program = `games.${fqn}` | ||
const message = 'flushEvents' | ||
|
||
let totalTime = 0 | ||
for (let index = 0; index < iterations; index++) | ||
totalTime += await measure(program, message) | ||
|
||
|
||
const time = totalTime / iterations | ||
const deltaError = expectedTime * 0.2 | ||
restore() | ||
|
||
// console.info(`${message} - ${fqn} - ${time} ms (${iterations} iterations)`) | ||
results.push({ message, fqn, time, iterations }) | ||
time.should.be.closeTo(expectedTime, deltaError) | ||
}) | ||
} | ||
|
||
benchmark('empty', 6) | ||
benchmark('visuals_1', 4.5) | ||
benchmark('visuals_100', 4.5) | ||
benchmark('ticks_1', 12) | ||
benchmark('ticks_100', 657) | ||
benchmark('onCollide_1', 11) | ||
benchmark('onCollide_10_same_position', 5000) | ||
benchmark('onCollide_100_diff_positions', 675) | ||
|
||
}) | ||
}) | ||
|
||
async function measure(programFQN: string, message: string): Promise<number> { | ||
const environment = await buildEnvironment(`**/*.${PROGRAM_FILE_EXTENSION}`, resolve('language', 'benchmarks')) | ||
const interpreter = interpret(environment, natives) | ||
|
||
interpreter.run(programFQN) | ||
const game = interpreter.object('wollok.game.game') | ||
|
||
interpreter.send(message, game, interpreter.reify(0)) // Fill caches | ||
const startTime = performance.now() | ||
for (let ms = 1; ms < 10; ms++) | ||
interpreter.send(message, game, interpreter.reify(ms)) | ||
const endTime = performance.now() | ||
|
||
const elapsedTime = endTime - startTime | ||
return elapsedTime | ||
} | ||