Skip to content
Snippets Groups Projects
Select Git revision
  • 8088667e6c8ab2c2f45aa5926adedb05cac798f2
  • master default protected
  • rednatco-v2
  • rednatco
  • test
  • ntc-tube-uniform-color
  • ntc-tube-missing-atoms
  • restore-vertex-array-per-program
  • watlas2
  • dnatco_new
  • cleanup-old-nodejs
  • webmmb
  • fix_auth_seq_id
  • update_deps
  • ext_dev
  • ntc_balls
  • nci-2
  • plugin
  • bugfix-0.4.5
  • nci
  • servers
  • v0.5.0-dev.1
  • v0.4.5
  • v0.4.4
  • v0.4.3
  • v0.4.2
  • v0.4.1
  • v0.4.0
  • v0.3.12
  • v0.3.11
  • v0.3.10
  • v0.3.9
  • v0.3.8
  • v0.3.7
  • v0.3.6
  • v0.3.5
  • v0.3.4
  • v0.3.3
  • v0.3.2
  • v0.3.1
  • v0.3.0
41 results

chunked-array-vs-native.ts

Blame
  • chunked-array-vs-native.ts 1.48 KiB
    import * as B from 'benchmark'
    import { ChunkedArray } from 'mol-data/util'
    
    function testNative(size: number) {
        const xs = new Array(size);
        for (let i = 0; i < size; i++) xs[i] = i * i;
        return xs;
    }
    
    function testChunkedTyped(size: number, chunk: number) {
        const xs = ChunkedArray.create(Int32Array, 1, chunk);
        for (let i = 0; i < size; i++) ChunkedArray.add(xs, i * i);
        return ChunkedArray.compact(xs);
    }
    
    function testChunkedNative(size: number, chunk: number) {
        const xs = ChunkedArray.create(Array, 1, chunk);
        for (let i = 0; i < size; i++) ChunkedArray.add(xs, i * i);
        return ChunkedArray.compact(xs);
    }
    
    const suite = new B.Suite();
    
    const N = 70000;
    
    suite
        .add('native', () => testNative(N))
        // .add('chunkedT 0.1k', () => testChunkedTyped(N, 100, false))
        // .add('chunkedT 4k', () => testChunkedTyped(N, 4096, false))
        .add('chunkedT 4k lin', () => testChunkedTyped(N, 4096))
        // .add('chunkedT N / 2', () => testChunkedTyped(N, N / 2, false))
        // .add('chunkedT N', () => testChunkedTyped(N, N, false))
        // .add('chunkedT 2 * N', () => testChunkedTyped(N, 2 * N, false))
    
        .add('chunkedN N', () => testChunkedNative(N, N))
        .add('chunkedN 0.1k', () => testChunkedNative(N, 100))
        .add('chunkedN N / 2', () => testChunkedNative(N, N / 2))
        .add('chunkedN 2 * N', () => testChunkedNative(N, 2 * N))
        .on('cycle', (e: any) => {
            console.log(String(e.target));
        })
        .run();
    
    //console.log(testChunkedTyped(10, 16));