jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Document</title><script src="https://code.jquery.com/jquery-3.7.1.js"></script></head><body><div class="nav"><h1>Home</h1><a href="about.php">About</a><a href="contact.php">Contact</a></div><div class="main"><div id="section1" class="section"><h1>Section 1</h1><p class="text">Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, quos.</p><p class="text">Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, quos.</p><p class="text">Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, quos.</p><p class="text">Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, quos.</p><p class="text">Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, quos.</p><p class="text">Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, quos.</p></div><div id="section2" class="section"><h1>Section 2</h1><p class="text">Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, quos.</p><p class="text">Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, quos.</p><p class="text">Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, quos.</p><p class="text">Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, quos.</p><p class="text">Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, quos.</p><p class="text">Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, quos.</p></div></div><div class="comments"><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div><div class="comment"><h1>Comment Title</h1><h2><a href="./author">Author</a></h2><h3>Date</h3><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p><p class="text comment-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.<a href="link">Quisquam</a>, quos.</p></div></div></body></html>
"use strict";
(function() {
class BestJS
{
/**
* Construct a BestJS object based on the given selector.
*
* Construct a BestJS object quering the DOM to get the elements matching the given selector.
* It can also be used to create new DOM elements or wrapping the given DOM Element.
*
* @param {string|Element|Element[]} selector string containing the selector to retrieve the Element from the DOM,
* the Element from the DOM,
* or an array of DOM Elements
* @return {BestJS} The BestJS object wrapping the queried or given DOM elements.
*/
constructor(selector)
{
if (typeof selector === "string")
{
if (selector[0] === "<" && selector[selector.length - 1] === ">")
{
this.elements = [document.createElement(selector)];
}
else
{
this.elements = selectElements(document, selector);
}
this.length = this.elements.length;
}
else
{
this.length = 0;
}
}
}
function isSubArray(array, master)
{
let isSubArray;
for (let i = 0; i < array.length; i++)
{
isSubArray = false;
for (let j = 0; j < master.length; j++)
if (array[i] === master[j])
{
isSubArray = true;
break;
}
if (!isSubArray)
return false;
}
return true;
}
function selectElements(root, selector)
{
if (selector.includes(" ") || selector.includes(">") || selector.includes("+") || selector.includes("~"))
return document.querySelectorAll(selector);
// Simple selector
const noFirstChar = selector.substring(1);
if (!noFirstChar.includes("#") && !noFirstChar.includes("."))
{
if (selector[0] === "#")
{
const element = root.getElementById(noFirstChar);
if (element)
return [element];
return [];
}
if (selector[0] === ".")
return root.getElementsByClassName(noFirstChar);
return root.getElementsByTagName(selector);
}
let indexOfId = noFirstChar.indexOf("#");
let indexOfClass = noFirstChar.indexOf(".");
let startIndex = indexOfClass === -1 || indexOfId !== -1 && indexOfId < indexOfClass ? indexOfId : indexOfClass;
const elements = selector[0] === "#" ? [root.getElementById(noFirstChar.substring(0, startIndex))] :
selector[0] === "." ? root.getElementsByClassName(noFirstChar.substring(0, startIndex)) :
root.getElementsByTagName(selector.substring(0, startIndex));
if (elements.length === 0 || elements[0] === null)
return [];
let id = undefined;
const classes = [];
indexOfId = noFirstChar.indexOf("#", startIndex + 1);
indexOfClass = noFirstChar.indexOf(".", startIndex + 1);
let nextIndex = indexOfClass === -1 || indexOfId !== -1 && indexOfId < indexOfClass ? indexOfId : indexOfClass;
while (nextIndex !== -1)
{
if (noFirstChar[startIndex] === "#")
{
const newId = noFirstChar.substring(startIndex + 1, nextIndex);
if (id && id !== newId) return [];
id = newId;
}
else if (noFirstChar[startIndex] === ".")
classes.push(noFirstChar.substring(startIndex + 1, nextIndex));
startIndex = nextIndex;
indexOfId = noFirstChar.indexOf("#", startIndex + 1);
indexOfClass = noFirstChar.indexOf(".", startIndex + 1);
nextIndex = indexOfClass === -1 || indexOfId !== -1 && indexOfId < indexOfClass ? indexOfId : indexOfClass;
}
if (noFirstChar[startIndex] === "#")
{
const newId = noFirstChar.substring(startIndex + 1);
if (id && id !== newId) return [];
id = newId;
}
else if (noFirstChar[startIndex] === ".")
classes.push(noFirstChar.substring(startIndex + 1));
const finalElements = new Array(elements.length);
let index = 0;
if (id === undefined)
for (let i = 0; i < elements.length; i++)
{
if (isSubArray(classes, elements[i].classList))
finalElements[index++] = elements[i];
}
else if (classes.length === 0)
for (let i = 0; i < elements.length; i++)
{
if (elements[i].id === id)
finalElements[index++] = elements[i];
}
else
for (let i = 0; i < elements.length; i++)
{
if (elements[i].id === id && !isSubArray(classes, elements[i].classList))
finalElements[index++] = elements[i];
}
finalElements.length = index;
return finalElements;
}
function creator(selector)
{
return new BestJS(selector);
}
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined')
{
module.exports = BestJS
}
else
{
window.BestJS = creator;
window.$$ = creator;
}
})();
const loopSize = 100;
Ready to run.
Test | Ops/sec | |
---|---|---|
Simple id jQuery |
| ready |
Simple id BestJS |
| ready |
Simple id getElementById |
| ready |
Simple class jQuery |
| ready |
Simple class BestJS |
| ready |
Simple class getElementsByClassName |
| ready |
Complex query jQuery |
| ready |
Complex query BestJS |
| ready |
Complex query querySelectorAll |
| ready |
Subsequent siblings selector jQuery |
| ready |
Subsequent siblings selector BestJS |
| ready |
Subsequent siblings selector querySelectorAll |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.