var myFloat = 210.758375837345;
var negFloat = -15.8674937593462;
var pos = 0.0, neg = 0.0, posi = 0, negi = 0;
pos = myFloat.toFixed(2);
neg = negFloat.toFixed(2);
pos = myFloat.toPrecision(2);
neg = negFloat.toPrecision(2);
pos = Math.round(myFloat*100.0)/100.0;
neg = Math.round(negFloat*100.0)/100.0;
pos = (100.0*(myFloat < 0.0 ? myFloat - 0.005 : myFloat + 0.005) >> 0)/100.0;
neg = (100.0*(negFloat < 0.0 ? negFloat - 0.005 : negFloat + 0.005) >> 0)/100.0;
pos = (100.0*myFloat+0.5 >> 0)/100.0;
neg = (100.0*negFloat-0.5 >> 0)/100.0;
posi = myFloat.toFixed(0);
negi = negFloat.toFixed(0);
posi = Math.round(myFloat);
negi = Math.round(negFloat);
posi = (myFloat < 0.0 ? myFloat - 0.5 : myFloat + 0.5) >> 0;
negi = (negFloat < 0.0 ? negFloat - 0.5 : negFloat + 0.5) >> 0;
posi = myFloat+0.5 >> 0;
negi = negFloat-0.5 >> 0;
posi = Math.floor(myFloat);
negi = Math.floor(negFloat);
posi = Math.trunc(myFloat);
negi = Math.trunc(negFloat);
posi = myFloat | 0;
negi = negFloat | 0;
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
myFloat.toFixed(2) | |
myFloat.toPrecision(2) | |
Math.round(myFloat*100.0)/100.0 | |
Bitwise: signed round ± to 2 places | |
Bitwise: UNsigned round ± to 2 places | |
myFloat.toFixed(0) | |
Math.round() | |
Bitwise: signed round ± to int | |
Bitwise: UNsigned round ± to int | |
Math.floor() round down | |
Math.trunc() round toward zero | |
Bitwise: round toward zero |
Test name | Executions per second |
---|---|
myFloat.toFixed(2) | 976976.4 Ops/sec |
myFloat.toPrecision(2) | 1106340.1 Ops/sec |
Math.round(myFloat*100.0)/100.0 | 939800.3 Ops/sec |
Bitwise: signed round ± to 2 places | 1197993.5 Ops/sec |
Bitwise: UNsigned round ± to 2 places | 1665880.1 Ops/sec |
myFloat.toFixed(0) | 1019422.8 Ops/sec |
Math.round() | 1025757.7 Ops/sec |
Bitwise: signed round ± to int | 1320582.8 Ops/sec |
Bitwise: UNsigned round ± to int | 1879278.6 Ops/sec |
Math.floor() round down | 1026371.3 Ops/sec |
Math.trunc() round toward zero | 1025808.0 Ops/sec |
Bitwise: round toward zero | 1884406.0 Ops/sec |
It seems like you're trying to parse JSON data. Here's the JSON data extracted and formatted for better readability:
[
{
"RawUAString": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Mobile Safari/537.36",
"Browser": "Chrome Mobile 117",
"DevicePlatform": "Mobile",
"OperatingSystem": "Android",
"ExecutionsPerSecond": 1665880.125,
"TestName": "Bitwise: UNsigned round ± to 2 places "
},
{
"RawUAString": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Mobile Safari/537.36",
"Browser": "Chrome Mobile 117",
"DevicePlatform": "Mobile",
"OperatingSystem": "Android",
"ExecutionsPerSecond": 1320582.75,
"TestName": "Bitwise: signed round ± to int"
},
{
"RawUAString": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Mobile Safari/537.36",
"Browser": "Chrome Mobile 117",
"DevicePlatform": "Mobile",
"OperatingSystem": "Android",
"ExecutionsPerSecond": 1197993.5,
"TestName": "Bitwise: signed round ± to 2 places "
},
{
"RawUAString": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Mobile Safari/537.36",
"Browser": "Chrome Mobile 117",
"DevicePlatform": "Mobile",
"OperatingSystem": "Android",
"ExecutionsPerSecond": 1106340.125,
"TestName": "myFloat.toPrecision(2) "
},
{
"RawUAString": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Mobile Safari/537.36",
"Browser": "Chrome Mobile 117",
"DevicePlatform": "Mobile",
"OperatingSystem": "Android",
"ExecutionsPerSecond": 1026371.3125,
"TestName": "Math.floor() round down"
},
{
"RawUAString": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Mobile Safari/537.36",
"Browser": "Chrome Mobile 117",
"DevicePlatform": "Mobile",
"OperatingSystem": "Android",
"ExecutionsPerSecond": 1025808.0,
"TestName": "Math.trunc() round toward zero"
},
{
"RawUAString": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Mobile Safari/537.36",
"Browser": "Chrome Mobile 117",
"DevicePlatform": "Mobile",
"OperatingSystem": "Android",
"ExecutionsPerSecond": 1025757.6875,
"TestName": "Math.round()"
},
{
"RawUAString": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Mobile Safari/537.36",
"Browser": "Chrome Mobile 117",
"DevicePlatform": "Mobile",
"OperatingSystem": "Android",
"ExecutionsPerSecond": 1019422.75,
"TestName": "myFloat.toFixed(0) "
},
{
"RawUAString": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Mobile Safari/537.36",
"Browser": "Chrome Mobile 117",
"DevicePlatform": "Mobile",
"OperatingSystem": "Android",
"ExecutionsPerSecond": 976976.4375,
"TestName": "myFloat.toFixed(2) "
},
{
"RawUAString": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Mobile Safari/537.36",
"Browser": "Chrome Mobile 117",
"DevicePlatform": "Mobile",
"OperatingSystem": "Android",
"ExecutionsPerSecond": 1665880.125,
"TestName": "Bitwise: UNsigned round ± to 2 places "
}
]
This JSON data contains multiple test results with different TestName
values, which seem to be related to testing various JavaScript operations involving unsigned and signed integers.