GithubHelp home page GithubHelp logo

5l1v3r1 / perflink Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lukejacksonn/perflink

0.0 1.0 0.0 189 KB

Low friction JavaScript benchmarks that you can share via URL

Home Page: https://perf.link

HTML 6.20% JavaScript 86.15% CSS 7.66%

perflink's Introduction

Perflink

JavaScript performance benchmarks you can share via URL

The motivation here was to create a single page app like jsperf โ€“ which is commonly used to compare performance characteristics of different Javascript code snippets โ€“ but with improved usability and portibility of results. It is a frontend only static web app with no build step and is hosted on Github pages.

perflink

Features

  • ๐Ÿงช Benchmarks run in isolated web workers
  • ๐ŸŒ Supports imports with worker type module
  • ๐Ÿ—‚ Saves test suites to local storage
  • ๐ŸŽจ Syntax highlighted textarea inputs
  • ๐Ÿ”— Serializable state encoded into shareable URLs
  • โฑ Adaptive timing for more accurate results
  • ๐Ÿ—œ Super light weight โ€“ almost no dependencies

Usage

To use the web interface simply visit https://perf.link and write out some test cases. When you are ready hit "Run Test". The code will be evaluated and benchmarked โ€“ against all other test cases โ€“ the results of which will appear on graph to the right.

The contents of all inputs and latest benchmark results for each test case, are stored in state which is serialised using the browsers atob function and set as the location.hash. This happens every time a benchmark is ran. That means you can share your findings with anyone by just copy pasting the window URL.

Development

If you would like to develop the project, first clone this repo then run the following command in your terminal (from the project root directory) which will open the app in your preferred browser.

$ npx servor --reload --browse

Live reload is enabled using the --reload flag with servor so when you make changes to your code the browser will reload the tab and your changes will be reflected there.

Implementation

Benchmarking involves accurate timing. Historically this has been hard to do due to the limitations of timers in JavaScript. Recently a high resolution timer was added by the WebPerf Working Group to allow measurement in the Web Platform with much greater degree of accuracy. Unfortunately, these timers became an attack vector for both Spectre and Meltdown and have since had their reolution reduced drastically (down to 1ms in Firefox) as well as jitter added. This makes them almost useless when it comes to benchmarking high performance code.

So instead, tests are now ran for a fixed duration of time (>1ms) and then the amount of times that the test ran for is multiplied up to give an operation per second reading. Here is the worker code for that calculation:

onmessage = async (e) => {
  const test = e.data[0]
  const duration = e.data[1]
  let result
  ;(async () => {
    try {
      result = await eval(`async () => {
        let ops = 0;
        let end = Date.now() + ${duration};
        while (Date.now() < end) {
          ${test.code};
          ops++;
        }
        return ops;
      }`)()
    } catch (e) {
      result = -1
    }
    postMessage(result === -1 ? result : (result * (1000 / duration)) << 0)
  })()
}

Benchmarking

Currently when the benchmark is ran, each tast case will be executed execute 100 times in its own worker. Before running the full test suite, each test case is executed 10 times in order to calculate the duration required to get a meaningful ops/s reading from each case. The max duration is then taken and each test case is executed for that amount of time. The mean average of running the full test suite is then recorded for each test case. When the tests are complete this data is surfaced next to the test code (as ops/s) and on the graph (as a % comparrison compared to all other test cases).

Contributing

If you have an idea for a new feature or find a bug then please feel free to create an issue or even better a pull request! I have a lot of projects to maintain but will try respond to every request.

perflink's People

Contributors

dielduarte avatar fredkschott avatar jevakallio avatar lukeed avatar lukejacksonn avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.