Skip to content

Commit e02de4a

Browse files
committed
src: enable libm trig functions in V8
Should provide better performance on some platforms.
1 parent b13f24c commit e02de4a

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

benchmark/util/trig.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
const { createBenchmark } = require('../common.js');
4+
const bench = createBenchmark(main, {
5+
n: 1_000_000,
6+
});
7+
8+
function main({ n }) {
9+
bench.start();
10+
let sum = 0;
11+
for (let i = 0; i < n; i++) {
12+
const result = Math.sin(Math.PI * i) * Math.cos(Math.PI * i);
13+
sum += result; // eslint-disable-line no-unused-vars
14+
}
15+
bench.end(n);
16+
}

common.gypi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@
7777

7878
'v8_win64_unwinding_info': 1,
7979

80+
'v8_use_libm_trig_functions': 1,
81+
8082
# Variables controlling external defines exposed in public headers.
8183
'v8_enable_map_packing%': 0,
8284
'v8_enable_pointer_compression_shared_cage%': 0,

test/parallel/test-trig.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
require('../common');
4+
const { strictEqual } = require('assert');
5+
6+
// Test to verify that the trig functions work as expected with the
7+
// v8_use_libm_trig_functions flag enabled.
8+
let sum = 0;
9+
for (let i = 0; i < 1_000_000; i++) {
10+
const result = Math.sin(Math.PI * i) * Math.cos(Math.PI * i);
11+
sum += result;
12+
};
13+
14+
strictEqual(sum, -0.00006123284579142155);

0 commit comments

Comments
 (0)