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
ASD
<!DOCTYPE html>
<html>
<head>
<script src="./scripts/lib/p5.latest.js"></script>
<script src="./scripts/lib/p5.dom.min.js"></script>
<script src="./scripts/lib/p5.sound.min.js"></script>
<script src="./scripts/lib/fontawesome-kit.js"></script> <!-- https://fontawesome.com/kits/60a456108b/icons -->
<link rel="stylesheet" type="text/css" href="style.css" />
<meta charset="utf-8" />
</head>
<body id="body">
<div id="nav"></div>
<script>
window.pointerLock = false
</script>
<script src="scripts/DevTools.js" defer></script>
<script src="scripts/DOMUtils.js" defer></script>
<script src="scripts/game_.js" defer></script>
<div id="output"></div>
<!-- <script src="sketch.js"></script>
-->
</body>
</html>
const { getFunctionCallString, findKeyByValue, colorParse, } = window.DOMUtils
class Game {
save = (instance) => {
localStorage.setItem(instance.id, JSON.stringify(instance))
alert(instance.id + " saved")
}
get = (instance) => JSON.parse(localStorage.getItem(instance.id || "myFirstGameSave"))
constructor() {
this.id = "myFirstGameSave"
this.House = {
Rooms: {
"Bedroom": {
description: "You are in your {r}Bedroom{/r}. There is a {o}Bed{/o}, a {o}Dresser{/o}, {r}Desk{/r}, and a door to the {r}Hall{/r}",
paths: ["Hallway", "Bathroom"],
inspects: ["Desk", "Bed", "Dresser"],
},
"Bathroom": {
description: "",
paths: ["Bedroom"],
inspects: ["Mirror"],
},
"Living Room": {
description: "",
paths: ["Kitchen", "Hallway", "Basement"],
inspects: ["Mirror"],
},
"Hallway": {
description: "A long hallway stretching about 10 feet is before you. You see a {y}Cloth{/y} over something that looks strangley like a person",
paths: ["Kitchen", "Hallway", "Basement"],
inspects: ["Lamp_hidden", "Painting_shown"],
}
},
Inspects: {
Desk: {
description: "The desk is made of {r}wood{/r} and has a {y}cloth{/y} on top of it. There is a {y}note{/y} on the desk",
onInspect: (instance) => { },
},
Bed: {
description: "Your Bed is unmade, books laden everywhere.",
onInspect: (instance) => { },
},
Dresser: {},
Mirror: {},
Lamp: {},
//add
},
Items: {}
}
this.Player = {
world: "House",
room: "Bedroom",
view: "Room", // can be Room | Event | Inventory | Map
inventory: ["Knife", "Gun", "Phone"],
health: 100,
fear: 0
}
this.Worlds = {
House: this.House
}
}
getWorld = (world) => {
return this.Worlds[world]
}
getPlayerWorld = () => this.Worlds[this.Player.world]
getWorldInspects = () => this.getWorld(this.Player.world).Inspects
getWorldRooms = () => this.getWorld(this.Player.world).Rooms
getWorldItems = () => this.getWorld(this.Player.world).Items
getPlayerRoom = () => this.getPlayerWorld().Rooms[this.Player.room]
getRoomInspects = () => {
let inspects = this.getPlayerRoom().inspects
const Inspects = this.getWorldInspects()
return inspects.map((inspect) => {
if (Object.hasOwn(Inspects, inspect) && JSON.stringify(Inspects[inspect]) !== `{}`) {
console.log(Inspects[inspect])
return Inspects[inspect]
}
return `add Inspect for ${inspect} referenced by ${this.Player.room} in ${this.Player.world}`
})
}
getRoomPaths = () => {
let paths = this.getPlayerRoom().paths
const RoomPaths = this.getWorldRooms()
return paths.map((room) => {
if (Object.hasOwn(RoomPaths, room)) {
return RoomPaths[room]
}
return `add Room for ${room} referenced by ${this.Player.room} at ${this.Player.world} `
})
}
// At World Level, Inspects \ Items \ Room
getAllFromWorld(key) {
return Object.keys(this.Worlds).map(worldKey => this.Worlds[worldKey][key]).flat()
}
setView(viewType) { // viewType can be Room | Event | Inventory | Map'
this.Player.view = viewType
return this
}
}
const game = new Game()
const appendData = (data, name) => {
const output = document.getElementById('output')
const title = document.createElement("h2")
title.textContent = getFunctionCallString(name)
const div = document.createElement("pre")
const prettyJson = JSON.stringify(data, null, 2)
div.textContent = prettyJson
output.append(title)
output.append(div)
}
const addButton = (parentId, functionName, callback) => {
const button = document.createElement("button")
button.setAttribute('id', functionName)
button.textContent = functionName
const parent = document.getElementById(parentId)
parent.prepend(button)
button.addEventListener('click', () => {
appendData(callback(), functionName)
})
}
Object.getOwnPropertyNames(game).forEach((key) => {
if (typeof game[key] === 'function') {
addButton('nav', game[key].name, () => {
if(game[key].name === 'save'){
return game[key](game)
} else {
return game[key](game[key].name)
}
})
}
if (typeof game[key] !== 'function') {
addButton('nav', key, () => game[key])
}
})
const clear = document.createElement('button')
clear.textContent = 'Clear'
clear.id = 'clear'
document.getElementById('nav').append(clear)
document.getElementById('clear').addEventListener('click', () => {
document.getElementById('output').innerHTML = ''
})
const gameCycle = () => {
const room = game.getPlayerRoom()
const inspects = game.getRoomInspects()
const directions = game.getRoomPaths()
document.getElementById('output').innerHTML = ``
}
Ready to run.
Test | Ops/sec | |
---|---|---|
ASD |
| ready |
ASD |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.