-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds ability to test example performance. Improoves spring-and-damper…
… force calculations which speeds up Wheel example. 15 seconds of simulation: BEFORE average was 3.77s (min 3.02s, max 4.16s), AFTER average is 3.12s (min 3.06s, max 3.27s).
- Loading branch information
1 parent
49773b3
commit 3935a87
Showing
10 changed files
with
156 additions
and
11 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
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,3 @@ | ||
// Copyright (c) 2018-2020 Robert Rypuła - https://github.com/robertrypula | ||
|
||
export const DEFAULT_EXAMPLE_FPS = 60; |
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,34 @@ | ||
// Copyright (c) 2018-2020 Robert Rypuła - https://github.com/robertrypula | ||
|
||
import { ExampleAdvancedWheel } from '@'; | ||
|
||
import { ExampleExecutionDetails } from '@examples/models'; | ||
import { getExampleExecutionDetails } from '@examples/tools'; | ||
|
||
describe('Advanced example - wheel', (): void => { | ||
it('should properly calculate wheel position', (): void => { | ||
const exampleExecutionDetails: ExampleExecutionDetails = getExampleExecutionDetails( | ||
ExampleAdvancedWheel, | ||
(example: ExampleAdvancedWheel): string => | ||
example.world.physics.time.toFixed(3) + 's: ' + example.wheel.center.position.toStringXY() | ||
); | ||
|
||
expect(exampleExecutionDetails.singleRunLog).toEqual([ | ||
'0.017s: 2.000 2.999', | ||
'1.017s: 1.269 2.157', | ||
'2.017s: -1.008 1.058', | ||
'3.017s: -4.006 -0.241', | ||
'4.017s: -2.011 -0.511', | ||
'5.017s: -2.035 -0.197', | ||
'6.017s: -4.041 -0.373', | ||
'7.017s: -2.314 -0.459', | ||
'8.017s: -2.052 -0.437', | ||
'9.017s: -2.199 -0.542', | ||
'10.017s: -2.980 -0.529', | ||
'11.017s: -3.751 -0.531', | ||
'12.017s: -3.830 -0.544', | ||
'13.017s: -3.577 -0.531', | ||
'14.017s: -3.328 -0.530' | ||
]); | ||
}); | ||
}); |
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,15 @@ | ||
// Copyright (c) 2018-2020 Robert Rypuła - https://github.com/robertrypula | ||
|
||
import { AbstractExample } from '@examples/abstract-example'; | ||
|
||
export interface ExampleExecutionDetails { | ||
runTime: { | ||
average: number; | ||
max: number; | ||
min: number; | ||
}; | ||
runTimes: number[]; | ||
singleRunLog: string[]; | ||
} | ||
|
||
export type ExampleFactory = new () => AbstractExample; |
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 |
---|---|---|
@@ -1,8 +1,18 @@ | ||
// Copyright (c) 2018-2020 Robert Rypuła - https://github.com/robertrypula | ||
|
||
import { ExampleAdvancedWheel } from '@examples/example-advanced-wheel'; | ||
import { ExampleExecutionDetails } from '@examples/models'; | ||
import { getExampleExecutionDetails } from '@examples/tools'; | ||
|
||
export class CliNodeExample { | ||
public constructor() { | ||
const exampleExecutionDetails: ExampleExecutionDetails = getExampleExecutionDetails( | ||
ExampleAdvancedWheel, | ||
(example: ExampleAdvancedWheel): string => | ||
example.world.physics.time.toFixed(3) + 's: ' + example.wheel.center.position.toStringXY() | ||
); | ||
|
||
/*tslint:disable-next-line:no-console*/ | ||
console.log('Hello World!'); | ||
console.log(exampleExecutionDetails); | ||
} | ||
} |
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,45 @@ | ||
// Copyright (c) 2018-2020 Robert Rypuła - https://github.com/robertrypula | ||
|
||
import { AbstractExample } from '@examples/abstract-example'; | ||
import { DEFAULT_EXAMPLE_FPS } from '@examples/constants'; | ||
import { ExampleExecutionDetails } from '@examples/models'; | ||
import { getTime } from '@shared/tools'; | ||
|
||
export const getExampleExecutionDetails = <T extends AbstractExample>( | ||
exampleFactory: new () => T, | ||
logHandler: (example: T) => string = null, | ||
runs = 1, | ||
seconds = 15, | ||
fps = DEFAULT_EXAMPLE_FPS | ||
): ExampleExecutionDetails => { | ||
const dt: number = 1 / fps; | ||
const timeStart: number = getTime(); | ||
const exampleExecutionDetails: ExampleExecutionDetails = { | ||
runTime: { | ||
average: null, | ||
max: null, | ||
min: null | ||
}, | ||
runTimes: [], | ||
singleRunLog: [] | ||
}; | ||
|
||
for (let run = 0; run < runs; run++) { | ||
const timeSubStart: number = getTime(); | ||
const example: T = new exampleFactory(); | ||
|
||
for (let second = 0; second < seconds; second++) { | ||
for (let frame = 0; frame < fps; frame++) { | ||
example.animationFrame(dt); | ||
|
||
run === 0 && frame === 0 && logHandler && exampleExecutionDetails.singleRunLog.push(logHandler(example)); | ||
} | ||
} | ||
exampleExecutionDetails.runTimes.push(getTime() - timeSubStart); | ||
} | ||
exampleExecutionDetails.runTime.average = (getTime() - timeStart) / runs; | ||
exampleExecutionDetails.runTime.max = Math.max(...exampleExecutionDetails.runTimes); | ||
exampleExecutionDetails.runTime.min = Math.min(...exampleExecutionDetails.runTimes); | ||
|
||
return exampleExecutionDetails; | ||
}; |
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