-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
workflow: add quick benchmark (#266)
- Loading branch information
Showing
19 changed files
with
747 additions
and
103 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
results/* |
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
File renamed without changes.
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,17 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vue Vapor Benchmark</title> | ||
<style> | ||
html { | ||
color-scheme: light dark; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="./index.ts"></script> | ||
</body> | ||
</html> |
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,5 @@ | ||
if (import.meta.env.IS_VAPOR) { | ||
import('./vapor') | ||
} else { | ||
import('./vdom') | ||
} |
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,79 @@ | ||
/* eslint-disable no-console */ | ||
/* eslint-disable no-restricted-syntax */ | ||
/* eslint-disable no-restricted-globals */ | ||
|
||
declare module globalThis { | ||
let doProfile: boolean | ||
let recordTime: boolean | ||
let times: Record<string, number[]> | ||
} | ||
|
||
globalThis.recordTime = true | ||
globalThis.doProfile = false | ||
|
||
export const defer = () => new Promise(r => requestIdleCallback(r)) | ||
|
||
const times: Record<string, number[]> = (globalThis.times = {}) | ||
|
||
export function wrap( | ||
id: string, | ||
fn: (...args: any[]) => any, | ||
): (...args: any[]) => Promise<void> { | ||
return async (...args) => { | ||
if (!globalThis.recordTime) { | ||
return fn(...args) | ||
} | ||
|
||
document.body.classList.remove('done') | ||
|
||
const { doProfile } = globalThis | ||
await defer() | ||
|
||
doProfile && console.profile(id) | ||
const start = performance.now() | ||
fn(...args) | ||
|
||
await defer() | ||
const time = performance.now() - start | ||
const prevTimes = times[id] || (times[id] = []) | ||
prevTimes.push(time) | ||
|
||
const { min, max, median, mean, std } = compute(prevTimes) | ||
const msg = | ||
`${id}: min: ${min} / ` + | ||
`max: ${max} / ` + | ||
`median: ${median}ms / ` + | ||
`mean: ${mean}ms / ` + | ||
`time: ${time.toFixed(2)}ms / ` + | ||
`std: ${std} ` + | ||
`over ${prevTimes.length} runs` | ||
doProfile && console.profileEnd(id) | ||
console.log(msg) | ||
const timeEl = document.getElementById('time')! | ||
timeEl.textContent = msg | ||
|
||
document.body.classList.add('done') | ||
} | ||
} | ||
|
||
function compute(array: number[]) { | ||
const n = array.length | ||
const max = Math.max(...array) | ||
const min = Math.min(...array) | ||
const mean = array.reduce((a, b) => a + b) / n | ||
const std = Math.sqrt( | ||
array.map(x => Math.pow(x - mean, 2)).reduce((a, b) => a + b) / n, | ||
) | ||
const median = array.slice().sort((a, b) => a - b)[Math.floor(n / 2)] | ||
return { | ||
max: round(max), | ||
min: round(min), | ||
mean: round(mean), | ||
std: round(std), | ||
median: round(median), | ||
} | ||
} | ||
|
||
function round(n: number) { | ||
return +n.toFixed(2) | ||
} |
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,4 @@ | ||
import { createVaporApp } from '@vue/vapor' | ||
import App from './App.vue' | ||
|
||
createVaporApp(App as any).mount('#app') |
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,4 @@ | ||
import { createApp } from 'vue' | ||
import App from './App.vue' | ||
|
||
createApp(App).mount('#app') |
Oops, something went wrong.