Ex-Nihilo

Benchmark created on


Description

Comparison of BlackScript class initialization. Originally on jsperf.com/ex-nihilo See blog post here: https://jwilliamdunn.blogspot.com/2018/07/blackscript.html

Setup

  const pageRecord = {
    createNew(id, pgNum, svg) {
      return {
        id: id,
        pageNumber: pgNum,
        size: 0,
        svg: svg,
        img: '',
        isImgLoading: false,
        isImgLoaded: false,
        isSvgLoading: false,
        isSvgLoaded: false,
        renderPlaceholder: true,
        renderSvg: false,
        renderImg: false,
        inlineSvg: ''
      }
    }
  };
  
  class pageClass {
    constructor ({
      id,
      pageNumber,
      svg
    }) {
      this.id = id
      this.pageNumber = pageNumber
      this.svg = svg
      this.size = 0
      this.img = ''
      this.isImgLoading = false
      this.isImgLoaded = false
      this.isSvgLoading = false
      this.isSvgLoaded = false
      this.renderPlaceholder = true
      this.renderSvg = false
      this.renderImg = false
      this.inlineSvg = ''
    }
  }
  
  function pageFunction(id, pageNumber, svg) {
    this.id = id
    this.pageNumber = pageNumber
    this.svg = svg
    this.size = 0
    this.img = ''
    this.isImgLoading = false
    this.isImgLoaded = false
    this.isSvgLoading = false
    this.isSvgLoaded = false
    this.renderPlaceholder = true
    this.renderSvg = false
    this.renderImg = false
    this.inlineSvg = ''
  }   

Test runner

Ready to run.

Testing in
TestOps/sec
OldClassStyle
let OldStyleClass = function() {
  const pages = new Array(1000);
  for (let i = 0, max = 1000; i < max; i++) {
    const p = new pageFunction(
      i,
      i + 1,
      '/viewer/' + (i + 1) + '.svg'
    )
    pages[i] = p
  }
};
OldStyleClass();
ready
NewStyleClass
let NewStyleClass = function() {
  const pages = new Array(1000);
  for (let i = 0, max = 1000; i < max; i++) {
    const p = new pageClass({
      id: i,
      pageNumber: i + 1,
      svg: '/viewer/' + (i + 1) + '.svg'
    })
    pages[i] = p
  }
};
NewStyleClass();
ready
ExNihilo
let ExNihilo = function() {
  const pages = new Array(1000);
  for (let i = 0, max = 1000; i < max; i++) {
    const p = pageRecord.createNew(
      i,
      i + 1,
      '/viewer/' + (i + 1) + '.svg'
    )
    pages[i] = p
  }
};
ExNihilo();
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.