diff --git a/benchmark/util/trig.js b/benchmark/util/trig.js new file mode 100644 index 00000000000000..39cf10c7bb4dd1 --- /dev/null +++ b/benchmark/util/trig.js @@ -0,0 +1,16 @@ +'use strict'; + +const { createBenchmark } = require('../common.js'); +const bench = createBenchmark(main, { + n: 1_000_000, +}); + +function main({ n }) { + bench.start(); + let sum = 0; + for (let i = 0; i < n; i++) { + const result = Math.sin(Math.PI * i) * Math.cos(Math.PI * i); + sum += result; // eslint-disable-line no-unused-vars + } + bench.end(n); +} diff --git a/common.gypi b/common.gypi index 6dbe33f43f2d61..704a35530a83b4 100644 --- a/common.gypi +++ b/common.gypi @@ -77,6 +77,8 @@ 'v8_win64_unwinding_info': 1, + 'v8_use_libm_trig_functions': 1, + # Variables controlling external defines exposed in public headers. 'v8_enable_map_packing%': 0, 'v8_enable_pointer_compression_shared_cage%': 0, diff --git a/test/parallel/test-trig.js b/test/parallel/test-trig.js new file mode 100644 index 00000000000000..0600a0de9d3b0c --- /dev/null +++ b/test/parallel/test-trig.js @@ -0,0 +1,14 @@ +'use strict'; + +require('../common'); +const { strictEqual } = require('assert'); + +// Test to verify that the trig functions work as expected with the +// v8_use_libm_trig_functions flag enabled. +let sum = 0; +for (let i = 0; i < 1_000_000; i++) { + const result = Math.sin(Math.PI * i) * Math.cos(Math.PI * i); + sum += result; +}; + +strictEqual(sum, -0.00006123284579142155);