summaryrefslogtreecommitdiff
path: root/deps/v8/test/js-perf-test/TypedArrays/join.js
blob: 9f090e4331f436631e51da14c96ea28d4ff070f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

load('base.js');

function CreateBenchmarks(constructors, withSep) {
  return constructors.map(({ ctor, name }) =>
    new Benchmark(`Join${name}`, false, false, 0, CreateJoinFn(withSep),
                  CreateSetupFn(ctor), TearDown)
  );
}

const kInitialArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
let result;
let arrayToJoin = [];

function CreateSetupFn(constructor) {
  return () => {
    if (constructor == BigUint64Array || constructor == BigInt64Array) {
      arrayToJoin = constructor.from(kInitialArray, x => BigInt(Math.floor(x)));
    } else {
      arrayToJoin = new constructor(kInitialArray);
    }
  }
}

function CreateJoinFn(withSep) {
  if (withSep) {
    return () => result = arrayToJoin.join(',');
  } else {
    return () => result = arrayToJoin.join('');
  }
}

function TearDown() {
  arrayToJoin = void 0;
}