Establish a baseline for computation performance in JS. * Compute Engine calculations will be measured against this.
(randos: number[])
| 25 | * Compute Engine calculations will be measured against this. |
| 26 | */ |
| 27 | function jsBaseline(randos: number[]): number { |
| 28 | let start = globalThis.performance.now(); |
| 29 | for (let i = 0; i < 20; i++) { |
| 30 | randos = randos.map((n, i) => { |
| 31 | // Do some arithmetic calculations |
| 32 | if (i % 2 === 0) return (4 * n ** 2) / 3 + (3 * n) / 2 + 2; |
| 33 | // Trigonometry, log, exp |
| 34 | return Math.tan(n) + Math.log(Math.abs(n)) + Math.exp(n); |
| 35 | }); |
| 36 | } |
| 37 | return (globalThis.performance.now() - start) / 20; |
| 38 | } |
| 39 | |
| 40 | function ceBaseline(numRandos: number[]): number { |
| 41 | const ce = new ComputeEngine(); |