| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d44a812 commit f40b5ed
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,36 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const common = require('../common.js'); | ||
| 5 | + | ||
| 6 | + const { | ||
| 7 | + PerformanceObserver, | ||
| 8 | + performance, | ||
| 9 | + } = require('perf_hooks'); | ||
| 10 | + | ||
| 11 | + function randomFn() { | ||
| 12 | + return Math.random(); | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + const bench = common.createBenchmark(main, { | ||
| 16 | + n: [1e5], | ||
| 17 | + observe: ['function'], | ||
| 18 | + }); | ||
| 19 | + | ||
| 20 | + let _result; | ||
| 21 | + | ||
| 22 | + function main({ n, observe }) { | ||
| 23 | + const obs = new PerformanceObserver(() => { | ||
| 24 | + bench.end(n); | ||
| 25 | + }); | ||
| 26 | + obs.observe({ entryTypes: [observe], buffered: true }); | ||
| 27 | + | ||
| 28 | + const timerfied = performance.timerify(randomFn); | ||
| 29 | + | ||
| 30 | + bench.start(); | ||
| 31 | + for (let i = 0; i < n; i++) | ||
| 32 | + _result = timerfied(); | ||
| 33 | + | ||
| 34 | + // Avoid V8 deadcode (elimination) | ||
| 35 | + assert.ok(_result); | ||
| 36 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,6 @@ | |||
| 2 | 2 | ||
| 3 | 3 | const { | |
| 4 | 4 | ObjectDefineProperties, | |
| 5 | - ReflectConstruct, | ||
| 6 | 5 | Symbol, | |
| 7 | 6 | } = primordials; | |
| 8 | 7 | ||
@@ -25,14 +24,17 @@ const kEntryType = Symbol('PerformanceEntry.EntryType'); | |||
| 25 | 24 | const kStartTime = Symbol('PerformanceEntry.StartTime'); | |
| 26 | 25 | const kDuration = Symbol('PerformanceEntry.Duration'); | |
| 27 | 26 | const kDetail = Symbol('NodePerformanceEntry.Detail'); | |
| 27 | + const kSkipThrow = Symbol('kSkipThrow'); | ||
| 28 | 28 | ||
| 29 | 29 | function isPerformanceEntry(obj) { | |
| 30 | 30 | return obj?.[kName] !== undefined; | |
| 31 | 31 | } | |
| 32 | 32 | ||
| 33 | 33 | class PerformanceEntry { | |
| 34 | - constructor() { | ||
| 35 | - throw new ERR_ILLEGAL_CONSTRUCTOR(); | ||
| 34 | + constructor(skipThrowSymbol = undefined) { | ||
| 35 | + if (skipThrowSymbol !== kSkipThrow) { | ||
| 36 | + throw new ERR_ILLEGAL_CONSTRUCTOR(); | ||
| 37 | + } | ||
| 36 | 38 | } | |
| 37 | 39 | ||
| 38 | 40 | get name() { | |
@@ -92,9 +94,11 @@ function initPerformanceEntry(entry, name, type, start, duration) { | |||
| 92 | 94 | } | |
| 93 | 95 | ||
| 94 | 96 | function createPerformanceEntry(name, type, start, duration) { | |
| 95 | - return ReflectConstruct(function PerformanceEntry() { | ||
| 96 | - initPerformanceEntry(this, name, type, start, duration); | ||
| 97 | - }, [], PerformanceEntry); | ||
| 97 | + const entry = new PerformanceEntry(kSkipThrow); | ||
| 98 | + | ||
| 99 | + initPerformanceEntry(entry, name, type, start, duration); | ||
| 100 | + | ||
| 101 | + return entry; | ||
| 98 | 102 | } | |
| 99 | 103 | ||
| 100 | 104 | /** | |
@@ -119,10 +123,12 @@ class PerformanceNodeEntry extends PerformanceEntry { | |||
| 119 | 123 | } | |
| 120 | 124 | ||
| 121 | 125 | function createPerformanceNodeEntry(name, type, start, duration, detail) { | |
| 122 | - return ReflectConstruct(function PerformanceNodeEntry() { | ||
| 123 | - initPerformanceEntry(this, name, type, start, duration); | ||
| 124 | - this[kDetail] = detail; | ||
| 125 | - }, [], PerformanceNodeEntry); | ||
| 126 | + const entry = new PerformanceNodeEntry(kSkipThrow); | ||
| 127 | + | ||
| 128 | + initPerformanceEntry(entry, name, type, start, duration); | ||
| 129 | + entry[kDetail] = detail; | ||
| 130 | + | ||
| 131 | + return entry; | ||
| 126 | 132 | } | |
| 127 | 133 | ||
| 128 | 134 | module.exports = { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments