Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>Measuring Performance</h1>
<p>
Click "Start Task" to simulate an asynchronous task and capture performance marks and a measure.
</p>

<p>
Click "Reset" to clear the performance timeline.
</p>

<button id="button">Start Task</button>
<button id="reset">Reset</button>

<ul>
  
</ul>
              
            
!

CSS

              
                * {
  font-family: Arial, sans-serif;
}

pre {
  font-family: Courier New, monospace;
  background: #333;
  color: white;
}

details {
  padding: 8px;
}

@keyframes appear {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  
  to {
    opacity: 1;
    transform: scale(1);
  }
}

button {
  background: #4338ca;
  color: white;
  padding: 8px 16px;
  font-size: 1.2em;
  border: 1px solid transparent;
  border-radius: 5px;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.mark {
  border: 1px solid gray;
  margin-top: 8px;
  margin-right: 8px;
  border-radius: 3px;
  background: #e0f2fe;
  animation: appear 500ms;
}

.mark h2 {
  margin: 0;
  font-size: 1.25rem;
  background: #1e40af;
  color: white;
  padding: 8px;
}

.mark dl {
  font-size: 1.2rem;
  padding: 8px;
  display: grid;
  grid-template-columns: auto 1fr;
  margin: 0;
}

.mark dt {
  font-weight: bold;
}

.mark dd {
  font-family: Courier, monospace;
}

.measure {
  background: #dcfce7;
}

.measure h2 {
  background: #166534;
}
              
            
!

JS

              
                const button = document.querySelector('#button');
const reset = document.querySelector('#reset');
const list = document.querySelector('ul');

let taskId = 1;

function showMark(mark) {
  const el = document.createElement('li');
  el.className = 'mark';

  el.innerHTML = `
    <h2>Performance Mark</h2>
    <dl>
      <dt>Name</dt>
      <dd>${mark.name}</dd>
      <dt>Start Time</dt>
      <dd>${mark.startTime}</dd>
    </dl>
    <details>
      <summary>Full entry details</summary>
      <pre>${JSON.stringify(mark, null, 2)}</pre>
    </details>
  `;
  
  list.insertBefore(el, list.firstElementChild);
}

function showMeasure(measure, startMark, endMark) {
  const el = document.createElement('li');
  el.className = 'measure mark';

  el.innerHTML = `
    <h2>Performance Measure</h2>
    <dl>
      <dt>Name</dt>
      <dd>${measure.name}</dd>
      <dt>Start Mark</dt>
      <dd>${startMark}</dd>
      <dt>End Mark</dt>
      <dd>${endMark}</dd>
      <dt>Duration</dt>
      <dd>${measure.duration}</dd>
    </dl>
    <details>
      <summary>Full entry details</summary>
      <pre>${JSON.stringify(measure, null, 2)}</pre>
    </details>
  `;
  
  list.insertBefore(el, list.firstElementChild);
}

reset.addEventListener('click', () => {
  performance.clearMarks();
  performance.clearMeasures();
  
  list.replaceChildren();
});

button.addEventListener('click', () => {
  button.disabled = true;
  const startMark = performance.mark(`task-${taskId}-start`);
  showMark(startMark);
  
  const delay = Math.random() * 4000;
  setTimeout(() => {
    const endMark = performance.mark(`task-${taskId}-end`);
    showMark(endMark);
    const measure = performance.measure(`task-${taskId}`, `task-${taskId}-start`, `task-${taskId}-end`);
    setTimeout(() => showMeasure(measure, `task-${taskId}-start`, `task-${taskId}-end`), 200);
    taskId++;
    button.disabled = false;
  }, delay);
});

              
            
!
999px

Console