MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Performance API (performance.mark & measure)0%
Study Materials
JavaScript for AdvancedProgress 0%
1.1Higher-Order Functions & Currying1.2Function Composition & Pipelining1.3Memoization & Pure Functions1.4Execution Context & Call Stack Deep Dive1.5Scope Chain & Lexical Environment
16.1Performance API (performance.mark & measure)16.2Logging Architecture & Structured Log Levels16.3Integrating Error Tracking (Sentry/Monitoring Concepts)16.4Crash Reporting & Telemetry Buffering
HomeTutorialsJavaScript for AdvancedPerformance API (performance.mark & measure)
Logging Architecture & Structured Log Levels

Performance API (performance.mark & measure)

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study Materials

While console.time() and Date.now() are useful for rudimentary logging, real enterprise performance instrumentation requires sub-millisecond precision and integration with browser performance profiling tools. The User Timing API (performance.mark() and performance.measure()) is the W3C standard for benchmarking code execution.


1. High-Resolution Time: performance.now()

Date.now() returns time in whole milliseconds and is subject to system clock adjustments (NTP syncs).

In contrast, performance.now() returns a floating-point number representing milliseconds with microsecond resolution (accurate to thousandths of a millisecond), measured monotonically from page creation:

1const t0 = performance.now();
2executeComputation();
3const t1 = performance.now();
4 
5console.log(`Execution took ${(t1 - t0).toFixed(3)} ms`);
6// "Execution took 14.821 ms"

2. Using performance.mark() and performance.measure()

The User Timing API stores timestamped markers in the browser's high-speed Performance Timeline buffer:

1async function loadUserData(userId) {
2 // Step 1: Create starting timestamp marker
3 performance.mark('fetchUser:start');
4 
5 const res = await fetch(`/api/users/${userId}`);
6 const data = await res.json();
7 
8 // Step 2: Create ending timestamp marker
9 performance.mark('fetchUser:end');
10 
11 // Step 3: Measure the duration between the two marks
12 const measure = performance.measure(
13 'UserFetchDuration', // Measure Name
14 'fetchUser:start', // Start Mark
15 'fetchUser:end' // End Mark
16 );
17 
18 console.log(`User ${userId} fetched in ${measure.duration.toFixed(2)}ms`);
19}

3. Visualizing in DevTools Performance Panel

When you run a profile in the DevTools Performance panel, any performance.mark() and performance.measure() entries appear automatically in the Timings flame-chart lane, providing visual context alongside network requests and layout frames!


4. Collecting Measures with PerformanceObserver

Rather than polling, use a PerformanceObserver to stream performance measurements asynchronously to analytics servers:

1const observer = new PerformanceObserver((list) => {
2 for (const entry of list.getEntries()) {
3 console.log(`[Telemetry Metric] ${entry.name}: ${entry.duration.toFixed(2)}ms`);
4 // Send to DataDog / New Relic / Google Analytics:
5 sendAnalyticsMetric({
6 metricName: entry.name,
7 durationMs: entry.duration,
8 startTime: entry.startTime
9 });
10 }
11});
12 
13// Register observer for custom user timing measures
14observer.observe({ entryTypes: ['measure'] });

5. Cleaning Up Performance Markers

Clear the internal browser buffer to prevent memory buildup:

1// Clear specific marks and measures
2performance.clearMarks('fetchUser:start');
3performance.clearMeasures('UserFetchDuration');
4 
5// Or wipe all custom user timings:
6// performance.clearMarks();
7// performance.clearMeasures();

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
How does performance.now() differ from Date.now()?
Question 2
What method creates a named timestamp checkpoint in the browser's performance timeline?
Question 3
How do you calculate and record the duration between two performance marks?
Question 4
Where do custom User Timing marks and measures appear in Chrome DevTools?
Question 5
What API allows real-time asynchronous streaming of performance metric entries to telemetry collectors?
Next Lesson

Logging Architecture & Structured Log Levels

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Web Audio & MediaStream APIs BasicsLogging Architecture & Structured Log Levels

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master JavaScript for Advanced with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext