as-uint-n.js 1.96 KB
Newer Older
1 2 3 4 5 6
// Copyright 2019 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.

"use strict";

7
d8.file.execute('bigint-util.js');
8

9 10
let random_bigints = [];

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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
// This dummy ensures that the feedback for benchmark.run() in the Measure
// function from base.js is not monomorphic, thereby preventing the benchmarks
// below from being inlined. This ensures consistent behavior and comparable
// results.
new BenchmarkSuite('Prevent-Inline-Dummy', [10000], [
  new Benchmark('Prevent-Inline-Dummy', true, false, 0, () => {})
]);


[32, 64, 128, 256].forEach((d) => {
  new BenchmarkSuite(`AsUint64-${d}`, [1000], [
    new Benchmark(`AsUint64-${d}`, true, false, 0, TestAsUint64,
      () => SetUpTestAsUintN(d))
  ]);
});


[32, 64, 128, 256].forEach((d) => {
  new BenchmarkSuite(`AsUint32-${d}`, [1000], [
    new Benchmark(`AsUint32-${d}`, true, false, 0, TestAsUint32,
      () => SetUpTestAsUintN(d))
  ]);
});


[32, 64, 128, 256].forEach((d) => {
  new BenchmarkSuite(`AsUint8-${d}`, [1000], [
    new Benchmark(`AsUint8-${d}`, true, false, 0, TestAsUint8,
      () => SetUpTestAsUintN(d))
  ]);
});


function SetUpTestAsUintN(d) {
  random_bigints = [
    RandomBigIntWithBits(d),
    RandomBigIntWithBits(d),
    RandomBigIntWithBits(d),
    RandomBigIntWithBits(d),
    RandomBigIntWithBits(d),
    RandomBigIntWithBits(d),
    RandomBigIntWithBits(d),
    RandomBigIntWithBits(d)
  ];
}


function TestAsUint64() {
  let result = 0n;

  for (let i = 0; i < TEST_ITERATIONS; ++i) {
    result = BigInt.asUintN(64, random_bigints[i % 8]);
  }

  return result;
}


function TestAsUint32() {
  let result = 0n;

  for (let i = 0; i < TEST_ITERATIONS; ++i) {
    result = BigInt.asUintN(32, random_bigints[i % 8]);
  }

  return result;
}


function TestAsUint8() {
  let result = 0n;

  for (let i = 0; i < TEST_ITERATIONS; ++i) {
    result = BigInt.asUintN(8, random_bigints[i % 8]);
  }

  return result;
}