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
// 模拟函数(无实际业务逻辑)
function performAdminAction(user) {
return `Admin action for ${user.name}`;
}
function performUserAction(user) {
return `User action for ${user.name}`;
}
function handleInactiveUser(user) {
return `Inactive user ${user.name}`;
}
function handleNoUser() {
return 'No user';
}
// 生成测试数据
function generateUsers(n) {
const users = [];
for (let i = 0; i < n; i++) {
const isAdmin = i % 3 === 0;
const isActive = i % 5 !== 0;
users.push({
name: `User${i}`,
isActive,
permissions: isAdmin ? ['admin', 'read'] : ['read'],
});
}
// 添加 null 测试
users.push(null);
return users;
}
// 性能测试函数
function testPerformance(label, fn, users) {
console.time(label);
for (let i = 0; i < users.length; i++) {
fn(users[i]);
}
console.timeEnd(label);
}
Ready to run.
Test | Ops/sec | |
---|---|---|
原始写法 |
| ready |
优化后写法 |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.