Skip to content

Commit

Permalink
feat: cost time of parse
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Feb 1, 2024
1 parent c872a71 commit 49f1337
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion components/NavBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import { version } from '../package.json'
</div>

<div flex="~ gap-3">
<span text-gray font-mono>{{ parserVersion }}</span>
<span op-80>{{ +parseCost.toFixed(1) }} ms</span>
<span font-mono op-80>{{ parserVersion }}</span>
<button title="Toggle Left Layout" @click="toggleLeftLayout">
<div v-if="showLeftLayout" i-ri:layout-column-fill />
<div v-else i-ri:layout-left-line />
Expand Down
3 changes: 3 additions & 0 deletions composables/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const code = ref('')
export const ast = shallowRef<unknown>({})
export const error = shallowRef<unknown>()
export const rawOptions = ref('')
export const parseCost = ref(0)

export const showLeftLayout = useLocalStorage('show-left-layout', true)
export const showRightLayout = useLocalStorage('show-right-layout', true)
Expand Down Expand Up @@ -108,11 +109,13 @@ watch(
loading.value = 'load'
const ctx = await parserContext.value
loading.value = 'parse'
const t = window.performance.now()
ast.value = await currentParser.value.parse.call(
await ctx,
code.value,
options.value,
)
parseCost.value = window.performance.now() - t
error.value = null
// eslint-disable-next-line unicorn/catch-error-name
} catch (err) {
Expand Down

0 comments on commit 49f1337

Please sign in to comment.