1*5a6e8488SAndroid Build Coastguard Worker# Benchmarks 2*5a6e8488SAndroid Build Coastguard Worker 3*5a6e8488SAndroid Build Coastguard WorkerThe results of these benchmarks suggest that building this `bc` with 4*5a6e8488SAndroid Build Coastguard Workeroptimization at `-O3` with link-time optimization (`-flto`) will result in the 5*5a6e8488SAndroid Build Coastguard Workerbest performance. However, using `-march=native` can result in **WORSE** 6*5a6e8488SAndroid Build Coastguard Workerperformance. 7*5a6e8488SAndroid Build Coastguard Worker 8*5a6e8488SAndroid Build Coastguard Worker*Note*: all benchmarks were run four times, and the fastest run is the one 9*5a6e8488SAndroid Build Coastguard Workershown. Also, `[bc]` means whichever `bc` was being run, and the assumed working 10*5a6e8488SAndroid Build Coastguard Workerdirectory is the root directory of this repository. Also, this `bc` was at 11*5a6e8488SAndroid Build Coastguard Workerversion `3.0.0` while GNU `bc` was at version `1.07.1`, and all tests were 12*5a6e8488SAndroid Build Coastguard Workerconducted on an `x86_64` machine running Gentoo Linux with `clang` `9.0.1` as 13*5a6e8488SAndroid Build Coastguard Workerthe compiler. 14*5a6e8488SAndroid Build Coastguard Worker 15*5a6e8488SAndroid Build Coastguard Worker## Typical Optimization Level 16*5a6e8488SAndroid Build Coastguard Worker 17*5a6e8488SAndroid Build Coastguard WorkerThese benchmarks were run with both `bc`'s compiled with the typical `-O2` 18*5a6e8488SAndroid Build Coastguard Workeroptimizations and no link-time optimization. 19*5a6e8488SAndroid Build Coastguard Worker 20*5a6e8488SAndroid Build Coastguard Worker### Addition 21*5a6e8488SAndroid Build Coastguard Worker 22*5a6e8488SAndroid Build Coastguard WorkerThe command used was: 23*5a6e8488SAndroid Build Coastguard Worker 24*5a6e8488SAndroid Build Coastguard Worker``` 25*5a6e8488SAndroid Build Coastguard Workertests/script.sh bc add.bc 1 0 1 1 [bc] 26*5a6e8488SAndroid Build Coastguard Worker``` 27*5a6e8488SAndroid Build Coastguard Worker 28*5a6e8488SAndroid Build Coastguard WorkerFor GNU `bc`: 29*5a6e8488SAndroid Build Coastguard Worker 30*5a6e8488SAndroid Build Coastguard Worker``` 31*5a6e8488SAndroid Build Coastguard Workerreal 2.54 32*5a6e8488SAndroid Build Coastguard Workeruser 1.21 33*5a6e8488SAndroid Build Coastguard Workersys 1.32 34*5a6e8488SAndroid Build Coastguard Worker``` 35*5a6e8488SAndroid Build Coastguard Worker 36*5a6e8488SAndroid Build Coastguard WorkerFor this `bc`: 37*5a6e8488SAndroid Build Coastguard Worker 38*5a6e8488SAndroid Build Coastguard Worker``` 39*5a6e8488SAndroid Build Coastguard Workerreal 0.88 40*5a6e8488SAndroid Build Coastguard Workeruser 0.85 41*5a6e8488SAndroid Build Coastguard Workersys 0.02 42*5a6e8488SAndroid Build Coastguard Worker``` 43*5a6e8488SAndroid Build Coastguard Worker 44*5a6e8488SAndroid Build Coastguard Worker### Subtraction 45*5a6e8488SAndroid Build Coastguard Worker 46*5a6e8488SAndroid Build Coastguard WorkerThe command used was: 47*5a6e8488SAndroid Build Coastguard Worker 48*5a6e8488SAndroid Build Coastguard Worker``` 49*5a6e8488SAndroid Build Coastguard Workertests/script.sh bc subtract.bc 1 0 1 1 [bc] 50*5a6e8488SAndroid Build Coastguard Worker``` 51*5a6e8488SAndroid Build Coastguard Worker 52*5a6e8488SAndroid Build Coastguard WorkerFor GNU `bc`: 53*5a6e8488SAndroid Build Coastguard Worker 54*5a6e8488SAndroid Build Coastguard Worker``` 55*5a6e8488SAndroid Build Coastguard Workerreal 2.51 56*5a6e8488SAndroid Build Coastguard Workeruser 1.05 57*5a6e8488SAndroid Build Coastguard Workersys 1.45 58*5a6e8488SAndroid Build Coastguard Worker``` 59*5a6e8488SAndroid Build Coastguard Worker 60*5a6e8488SAndroid Build Coastguard WorkerFor this `bc`: 61*5a6e8488SAndroid Build Coastguard Worker 62*5a6e8488SAndroid Build Coastguard Worker``` 63*5a6e8488SAndroid Build Coastguard Workerreal 0.91 64*5a6e8488SAndroid Build Coastguard Workeruser 0.85 65*5a6e8488SAndroid Build Coastguard Workersys 0.05 66*5a6e8488SAndroid Build Coastguard Worker``` 67*5a6e8488SAndroid Build Coastguard Worker 68*5a6e8488SAndroid Build Coastguard Worker### Multiplication 69*5a6e8488SAndroid Build Coastguard Worker 70*5a6e8488SAndroid Build Coastguard WorkerThe command used was: 71*5a6e8488SAndroid Build Coastguard Worker 72*5a6e8488SAndroid Build Coastguard Worker``` 73*5a6e8488SAndroid Build Coastguard Workertests/script.sh bc multiply.bc 1 0 1 1 [bc] 74*5a6e8488SAndroid Build Coastguard Worker``` 75*5a6e8488SAndroid Build Coastguard Worker 76*5a6e8488SAndroid Build Coastguard WorkerFor GNU `bc`: 77*5a6e8488SAndroid Build Coastguard Worker 78*5a6e8488SAndroid Build Coastguard Worker``` 79*5a6e8488SAndroid Build Coastguard Workerreal 7.15 80*5a6e8488SAndroid Build Coastguard Workeruser 4.69 81*5a6e8488SAndroid Build Coastguard Workersys 2.46 82*5a6e8488SAndroid Build Coastguard Worker``` 83*5a6e8488SAndroid Build Coastguard Worker 84*5a6e8488SAndroid Build Coastguard WorkerFor this `bc`: 85*5a6e8488SAndroid Build Coastguard Worker 86*5a6e8488SAndroid Build Coastguard Worker``` 87*5a6e8488SAndroid Build Coastguard Workerreal 2.20 88*5a6e8488SAndroid Build Coastguard Workeruser 2.10 89*5a6e8488SAndroid Build Coastguard Workersys 0.09 90*5a6e8488SAndroid Build Coastguard Worker``` 91*5a6e8488SAndroid Build Coastguard Worker 92*5a6e8488SAndroid Build Coastguard Worker### Division 93*5a6e8488SAndroid Build Coastguard Worker 94*5a6e8488SAndroid Build Coastguard WorkerThe command used was: 95*5a6e8488SAndroid Build Coastguard Worker 96*5a6e8488SAndroid Build Coastguard Worker``` 97*5a6e8488SAndroid Build Coastguard Workertests/script.sh bc divide.bc 1 0 1 1 [bc] 98*5a6e8488SAndroid Build Coastguard Worker``` 99*5a6e8488SAndroid Build Coastguard Worker 100*5a6e8488SAndroid Build Coastguard WorkerFor GNU `bc`: 101*5a6e8488SAndroid Build Coastguard Worker 102*5a6e8488SAndroid Build Coastguard Worker``` 103*5a6e8488SAndroid Build Coastguard Workerreal 3.36 104*5a6e8488SAndroid Build Coastguard Workeruser 1.87 105*5a6e8488SAndroid Build Coastguard Workersys 1.48 106*5a6e8488SAndroid Build Coastguard Worker``` 107*5a6e8488SAndroid Build Coastguard Worker 108*5a6e8488SAndroid Build Coastguard WorkerFor this `bc`: 109*5a6e8488SAndroid Build Coastguard Worker 110*5a6e8488SAndroid Build Coastguard Worker``` 111*5a6e8488SAndroid Build Coastguard Workerreal 1.61 112*5a6e8488SAndroid Build Coastguard Workeruser 1.57 113*5a6e8488SAndroid Build Coastguard Workersys 0.03 114*5a6e8488SAndroid Build Coastguard Worker``` 115*5a6e8488SAndroid Build Coastguard Worker 116*5a6e8488SAndroid Build Coastguard Worker### Power 117*5a6e8488SAndroid Build Coastguard Worker 118*5a6e8488SAndroid Build Coastguard WorkerThe command used was: 119*5a6e8488SAndroid Build Coastguard Worker 120*5a6e8488SAndroid Build Coastguard Worker``` 121*5a6e8488SAndroid Build Coastguard Workerprintf '1234567890^100000; halt\n' | time -p [bc] -q > /dev/null 122*5a6e8488SAndroid Build Coastguard Worker``` 123*5a6e8488SAndroid Build Coastguard Worker 124*5a6e8488SAndroid Build Coastguard WorkerFor GNU `bc`: 125*5a6e8488SAndroid Build Coastguard Worker 126*5a6e8488SAndroid Build Coastguard Worker``` 127*5a6e8488SAndroid Build Coastguard Workerreal 11.30 128*5a6e8488SAndroid Build Coastguard Workeruser 11.30 129*5a6e8488SAndroid Build Coastguard Workersys 0.00 130*5a6e8488SAndroid Build Coastguard Worker``` 131*5a6e8488SAndroid Build Coastguard Worker 132*5a6e8488SAndroid Build Coastguard WorkerFor this `bc`: 133*5a6e8488SAndroid Build Coastguard Worker 134*5a6e8488SAndroid Build Coastguard Worker``` 135*5a6e8488SAndroid Build Coastguard Workerreal 0.73 136*5a6e8488SAndroid Build Coastguard Workeruser 0.72 137*5a6e8488SAndroid Build Coastguard Workersys 0.00 138*5a6e8488SAndroid Build Coastguard Worker``` 139*5a6e8488SAndroid Build Coastguard Worker 140*5a6e8488SAndroid Build Coastguard Worker### Scripts 141*5a6e8488SAndroid Build Coastguard Worker 142*5a6e8488SAndroid Build Coastguard Worker[This file][1] was downloaded, saved at `../timeconst.bc` and the following 143*5a6e8488SAndroid Build Coastguard Workerpatch was applied: 144*5a6e8488SAndroid Build Coastguard Worker 145*5a6e8488SAndroid Build Coastguard Worker``` 146*5a6e8488SAndroid Build Coastguard Worker--- ../timeconst.bc 2018-09-28 11:32:22.808669000 -0600 147*5a6e8488SAndroid Build Coastguard Worker+++ ../timeconst.bc 2019-06-07 07:26:36.359913078 -0600 148*5a6e8488SAndroid Build Coastguard Worker@@ -110,8 +110,10 @@ 149*5a6e8488SAndroid Build Coastguard Worker 150*5a6e8488SAndroid Build Coastguard Worker print "#endif /* KERNEL_TIMECONST_H */\n" 151*5a6e8488SAndroid Build Coastguard Worker } 152*5a6e8488SAndroid Build Coastguard Worker- halt 153*5a6e8488SAndroid Build Coastguard Worker } 154*5a6e8488SAndroid Build Coastguard Worker 155*5a6e8488SAndroid Build Coastguard Worker-hz = read(); 156*5a6e8488SAndroid Build Coastguard Worker-timeconst(hz) 157*5a6e8488SAndroid Build Coastguard Worker+for (i = 0; i <= 50000; ++i) { 158*5a6e8488SAndroid Build Coastguard Worker+ timeconst(i) 159*5a6e8488SAndroid Build Coastguard Worker+} 160*5a6e8488SAndroid Build Coastguard Worker+ 161*5a6e8488SAndroid Build Coastguard Worker+halt 162*5a6e8488SAndroid Build Coastguard Worker``` 163*5a6e8488SAndroid Build Coastguard Worker 164*5a6e8488SAndroid Build Coastguard WorkerThe command used was: 165*5a6e8488SAndroid Build Coastguard Worker 166*5a6e8488SAndroid Build Coastguard Worker``` 167*5a6e8488SAndroid Build Coastguard Workertime -p [bc] ../timeconst.bc > /dev/null 168*5a6e8488SAndroid Build Coastguard Worker``` 169*5a6e8488SAndroid Build Coastguard Worker 170*5a6e8488SAndroid Build Coastguard WorkerFor GNU `bc`: 171*5a6e8488SAndroid Build Coastguard Worker 172*5a6e8488SAndroid Build Coastguard Worker``` 173*5a6e8488SAndroid Build Coastguard Workerreal 16.71 174*5a6e8488SAndroid Build Coastguard Workeruser 16.06 175*5a6e8488SAndroid Build Coastguard Workersys 0.65 176*5a6e8488SAndroid Build Coastguard Worker``` 177*5a6e8488SAndroid Build Coastguard Worker 178*5a6e8488SAndroid Build Coastguard WorkerFor this `bc`: 179*5a6e8488SAndroid Build Coastguard Worker 180*5a6e8488SAndroid Build Coastguard Worker``` 181*5a6e8488SAndroid Build Coastguard Workerreal 13.16 182*5a6e8488SAndroid Build Coastguard Workeruser 13.15 183*5a6e8488SAndroid Build Coastguard Workersys 0.00 184*5a6e8488SAndroid Build Coastguard Worker``` 185*5a6e8488SAndroid Build Coastguard Worker 186*5a6e8488SAndroid Build Coastguard WorkerBecause this `bc` is faster when doing math, it might be a better comparison to 187*5a6e8488SAndroid Build Coastguard Workerrun a script that is not running any math. As such, I put the following into 188*5a6e8488SAndroid Build Coastguard Worker`../test.bc`: 189*5a6e8488SAndroid Build Coastguard Worker 190*5a6e8488SAndroid Build Coastguard Worker``` 191*5a6e8488SAndroid Build Coastguard Workerfor (i = 0; i < 100000000; ++i) { 192*5a6e8488SAndroid Build Coastguard Worker y = i 193*5a6e8488SAndroid Build Coastguard Worker} 194*5a6e8488SAndroid Build Coastguard Worker 195*5a6e8488SAndroid Build Coastguard Workeri 196*5a6e8488SAndroid Build Coastguard Workery 197*5a6e8488SAndroid Build Coastguard Worker 198*5a6e8488SAndroid Build Coastguard Workerhalt 199*5a6e8488SAndroid Build Coastguard Worker``` 200*5a6e8488SAndroid Build Coastguard Worker 201*5a6e8488SAndroid Build Coastguard WorkerThe command used was: 202*5a6e8488SAndroid Build Coastguard Worker 203*5a6e8488SAndroid Build Coastguard Worker``` 204*5a6e8488SAndroid Build Coastguard Workertime -p [bc] ../test.bc > /dev/null 205*5a6e8488SAndroid Build Coastguard Worker``` 206*5a6e8488SAndroid Build Coastguard Worker 207*5a6e8488SAndroid Build Coastguard WorkerFor GNU `bc`: 208*5a6e8488SAndroid Build Coastguard Worker 209*5a6e8488SAndroid Build Coastguard Worker``` 210*5a6e8488SAndroid Build Coastguard Workerreal 16.60 211*5a6e8488SAndroid Build Coastguard Workeruser 16.59 212*5a6e8488SAndroid Build Coastguard Workersys 0.00 213*5a6e8488SAndroid Build Coastguard Worker``` 214*5a6e8488SAndroid Build Coastguard Worker 215*5a6e8488SAndroid Build Coastguard WorkerFor this `bc`: 216*5a6e8488SAndroid Build Coastguard Worker 217*5a6e8488SAndroid Build Coastguard Worker``` 218*5a6e8488SAndroid Build Coastguard Workerreal 22.76 219*5a6e8488SAndroid Build Coastguard Workeruser 22.75 220*5a6e8488SAndroid Build Coastguard Workersys 0.00 221*5a6e8488SAndroid Build Coastguard Worker``` 222*5a6e8488SAndroid Build Coastguard Worker 223*5a6e8488SAndroid Build Coastguard WorkerI also put the following into `../test2.bc`: 224*5a6e8488SAndroid Build Coastguard Worker 225*5a6e8488SAndroid Build Coastguard Worker``` 226*5a6e8488SAndroid Build Coastguard Workeri = 0 227*5a6e8488SAndroid Build Coastguard Worker 228*5a6e8488SAndroid Build Coastguard Workerwhile (i < 100000000) { 229*5a6e8488SAndroid Build Coastguard Worker i += 1 230*5a6e8488SAndroid Build Coastguard Worker} 231*5a6e8488SAndroid Build Coastguard Worker 232*5a6e8488SAndroid Build Coastguard Workeri 233*5a6e8488SAndroid Build Coastguard Worker 234*5a6e8488SAndroid Build Coastguard Workerhalt 235*5a6e8488SAndroid Build Coastguard Worker``` 236*5a6e8488SAndroid Build Coastguard Worker 237*5a6e8488SAndroid Build Coastguard WorkerThe command used was: 238*5a6e8488SAndroid Build Coastguard Worker 239*5a6e8488SAndroid Build Coastguard Worker``` 240*5a6e8488SAndroid Build Coastguard Workertime -p [bc] ../test2.bc > /dev/null 241*5a6e8488SAndroid Build Coastguard Worker``` 242*5a6e8488SAndroid Build Coastguard Worker 243*5a6e8488SAndroid Build Coastguard WorkerFor GNU `bc`: 244*5a6e8488SAndroid Build Coastguard Worker 245*5a6e8488SAndroid Build Coastguard Worker``` 246*5a6e8488SAndroid Build Coastguard Workerreal 17.32 247*5a6e8488SAndroid Build Coastguard Workeruser 17.30 248*5a6e8488SAndroid Build Coastguard Workersys 0.00 249*5a6e8488SAndroid Build Coastguard Worker``` 250*5a6e8488SAndroid Build Coastguard Worker 251*5a6e8488SAndroid Build Coastguard WorkerFor this `bc`: 252*5a6e8488SAndroid Build Coastguard Worker 253*5a6e8488SAndroid Build Coastguard Worker``` 254*5a6e8488SAndroid Build Coastguard Workerreal 16.98 255*5a6e8488SAndroid Build Coastguard Workeruser 16.96 256*5a6e8488SAndroid Build Coastguard Workersys 0.01 257*5a6e8488SAndroid Build Coastguard Worker``` 258*5a6e8488SAndroid Build Coastguard Worker 259*5a6e8488SAndroid Build Coastguard WorkerIt seems that the improvements to the interpreter helped a lot in certain cases. 260*5a6e8488SAndroid Build Coastguard Worker 261*5a6e8488SAndroid Build Coastguard WorkerAlso, I have no idea why GNU `bc` did worse when it is technically doing less 262*5a6e8488SAndroid Build Coastguard Workerwork. 263*5a6e8488SAndroid Build Coastguard Worker 264*5a6e8488SAndroid Build Coastguard Worker## Recommended Optimizations from `2.7.0` 265*5a6e8488SAndroid Build Coastguard Worker 266*5a6e8488SAndroid Build Coastguard WorkerNote that, when running the benchmarks, the optimizations used are not the ones 267*5a6e8488SAndroid Build Coastguard WorkerI recommended for version `2.7.0`, which are `-O3 -flto -march=native`. 268*5a6e8488SAndroid Build Coastguard Worker 269*5a6e8488SAndroid Build Coastguard WorkerThis `bc` separates its code into modules that, when optimized at link time, 270*5a6e8488SAndroid Build Coastguard Workerremoves a lot of the inefficiency that comes from function overhead. This is 271*5a6e8488SAndroid Build Coastguard Workermost keenly felt with one function: `bc_vec_item()`, which should turn into just 272*5a6e8488SAndroid Build Coastguard Workerone instruction (on `x86_64`) when optimized at link time and inlined. There are 273*5a6e8488SAndroid Build Coastguard Workerother functions that matter as well. 274*5a6e8488SAndroid Build Coastguard Worker 275*5a6e8488SAndroid Build Coastguard WorkerI also recommended `-march=native` on the grounds that newer instructions would 276*5a6e8488SAndroid Build Coastguard Workerincrease performance on math-heavy code. We will see if that assumption was 277*5a6e8488SAndroid Build Coastguard Workercorrect. (Spoiler: **NO**.) 278*5a6e8488SAndroid Build Coastguard Worker 279*5a6e8488SAndroid Build Coastguard WorkerWhen compiling both `bc`'s with the optimizations I recommended for this `bc` 280*5a6e8488SAndroid Build Coastguard Workerfor version `2.7.0`, the results are as follows. 281*5a6e8488SAndroid Build Coastguard Worker 282*5a6e8488SAndroid Build Coastguard Worker### Addition 283*5a6e8488SAndroid Build Coastguard Worker 284*5a6e8488SAndroid Build Coastguard WorkerThe command used was: 285*5a6e8488SAndroid Build Coastguard Worker 286*5a6e8488SAndroid Build Coastguard Worker``` 287*5a6e8488SAndroid Build Coastguard Workertests/script.sh bc add.bc 1 0 1 1 [bc] 288*5a6e8488SAndroid Build Coastguard Worker``` 289*5a6e8488SAndroid Build Coastguard Worker 290*5a6e8488SAndroid Build Coastguard WorkerFor GNU `bc`: 291*5a6e8488SAndroid Build Coastguard Worker 292*5a6e8488SAndroid Build Coastguard Worker``` 293*5a6e8488SAndroid Build Coastguard Workerreal 2.44 294*5a6e8488SAndroid Build Coastguard Workeruser 1.11 295*5a6e8488SAndroid Build Coastguard Workersys 1.32 296*5a6e8488SAndroid Build Coastguard Worker``` 297*5a6e8488SAndroid Build Coastguard Worker 298*5a6e8488SAndroid Build Coastguard WorkerFor this `bc`: 299*5a6e8488SAndroid Build Coastguard Worker 300*5a6e8488SAndroid Build Coastguard Worker``` 301*5a6e8488SAndroid Build Coastguard Workerreal 0.59 302*5a6e8488SAndroid Build Coastguard Workeruser 0.54 303*5a6e8488SAndroid Build Coastguard Workersys 0.05 304*5a6e8488SAndroid Build Coastguard Worker``` 305*5a6e8488SAndroid Build Coastguard Worker 306*5a6e8488SAndroid Build Coastguard Worker### Subtraction 307*5a6e8488SAndroid Build Coastguard Worker 308*5a6e8488SAndroid Build Coastguard WorkerThe command used was: 309*5a6e8488SAndroid Build Coastguard Worker 310*5a6e8488SAndroid Build Coastguard Worker``` 311*5a6e8488SAndroid Build Coastguard Workertests/script.sh bc subtract.bc 1 0 1 1 [bc] 312*5a6e8488SAndroid Build Coastguard Worker``` 313*5a6e8488SAndroid Build Coastguard Worker 314*5a6e8488SAndroid Build Coastguard WorkerFor GNU `bc`: 315*5a6e8488SAndroid Build Coastguard Worker 316*5a6e8488SAndroid Build Coastguard Worker``` 317*5a6e8488SAndroid Build Coastguard Workerreal 2.42 318*5a6e8488SAndroid Build Coastguard Workeruser 1.02 319*5a6e8488SAndroid Build Coastguard Workersys 1.40 320*5a6e8488SAndroid Build Coastguard Worker``` 321*5a6e8488SAndroid Build Coastguard Worker 322*5a6e8488SAndroid Build Coastguard WorkerFor this `bc`: 323*5a6e8488SAndroid Build Coastguard Worker 324*5a6e8488SAndroid Build Coastguard Worker``` 325*5a6e8488SAndroid Build Coastguard Workerreal 0.64 326*5a6e8488SAndroid Build Coastguard Workeruser 0.57 327*5a6e8488SAndroid Build Coastguard Workersys 0.06 328*5a6e8488SAndroid Build Coastguard Worker``` 329*5a6e8488SAndroid Build Coastguard Worker 330*5a6e8488SAndroid Build Coastguard Worker### Multiplication 331*5a6e8488SAndroid Build Coastguard Worker 332*5a6e8488SAndroid Build Coastguard WorkerThe command used was: 333*5a6e8488SAndroid Build Coastguard Worker 334*5a6e8488SAndroid Build Coastguard Worker``` 335*5a6e8488SAndroid Build Coastguard Workertests/script.sh bc multiply.bc 1 0 1 1 [bc] 336*5a6e8488SAndroid Build Coastguard Worker``` 337*5a6e8488SAndroid Build Coastguard Worker 338*5a6e8488SAndroid Build Coastguard WorkerFor GNU `bc`: 339*5a6e8488SAndroid Build Coastguard Worker 340*5a6e8488SAndroid Build Coastguard Worker``` 341*5a6e8488SAndroid Build Coastguard Workerreal 7.01 342*5a6e8488SAndroid Build Coastguard Workeruser 4.50 343*5a6e8488SAndroid Build Coastguard Workersys 2.50 344*5a6e8488SAndroid Build Coastguard Worker``` 345*5a6e8488SAndroid Build Coastguard Worker 346*5a6e8488SAndroid Build Coastguard WorkerFor this `bc`: 347*5a6e8488SAndroid Build Coastguard Worker 348*5a6e8488SAndroid Build Coastguard Worker``` 349*5a6e8488SAndroid Build Coastguard Workerreal 1.59 350*5a6e8488SAndroid Build Coastguard Workeruser 1.53 351*5a6e8488SAndroid Build Coastguard Workersys 0.05 352*5a6e8488SAndroid Build Coastguard Worker``` 353*5a6e8488SAndroid Build Coastguard Worker 354*5a6e8488SAndroid Build Coastguard Worker### Division 355*5a6e8488SAndroid Build Coastguard Worker 356*5a6e8488SAndroid Build Coastguard WorkerThe command used was: 357*5a6e8488SAndroid Build Coastguard Worker 358*5a6e8488SAndroid Build Coastguard Worker``` 359*5a6e8488SAndroid Build Coastguard Workertests/script.sh bc divide.bc 1 0 1 1 [bc] 360*5a6e8488SAndroid Build Coastguard Worker``` 361*5a6e8488SAndroid Build Coastguard Worker 362*5a6e8488SAndroid Build Coastguard WorkerFor GNU `bc`: 363*5a6e8488SAndroid Build Coastguard Worker 364*5a6e8488SAndroid Build Coastguard Worker``` 365*5a6e8488SAndroid Build Coastguard Workerreal 3.26 366*5a6e8488SAndroid Build Coastguard Workeruser 1.82 367*5a6e8488SAndroid Build Coastguard Workersys 1.44 368*5a6e8488SAndroid Build Coastguard Worker``` 369*5a6e8488SAndroid Build Coastguard Worker 370*5a6e8488SAndroid Build Coastguard WorkerFor this `bc`: 371*5a6e8488SAndroid Build Coastguard Worker 372*5a6e8488SAndroid Build Coastguard Worker``` 373*5a6e8488SAndroid Build Coastguard Workerreal 1.24 374*5a6e8488SAndroid Build Coastguard Workeruser 1.20 375*5a6e8488SAndroid Build Coastguard Workersys 0.03 376*5a6e8488SAndroid Build Coastguard Worker``` 377*5a6e8488SAndroid Build Coastguard Worker 378*5a6e8488SAndroid Build Coastguard Worker### Power 379*5a6e8488SAndroid Build Coastguard Worker 380*5a6e8488SAndroid Build Coastguard WorkerThe command used was: 381*5a6e8488SAndroid Build Coastguard Worker 382*5a6e8488SAndroid Build Coastguard Worker``` 383*5a6e8488SAndroid Build Coastguard Workerprintf '1234567890^100000; halt\n' | time -p [bc] -q > /dev/null 384*5a6e8488SAndroid Build Coastguard Worker``` 385*5a6e8488SAndroid Build Coastguard Worker 386*5a6e8488SAndroid Build Coastguard WorkerFor GNU `bc`: 387*5a6e8488SAndroid Build Coastguard Worker 388*5a6e8488SAndroid Build Coastguard Worker``` 389*5a6e8488SAndroid Build Coastguard Workerreal 11.08 390*5a6e8488SAndroid Build Coastguard Workeruser 11.07 391*5a6e8488SAndroid Build Coastguard Workersys 0.00 392*5a6e8488SAndroid Build Coastguard Worker``` 393*5a6e8488SAndroid Build Coastguard Worker 394*5a6e8488SAndroid Build Coastguard WorkerFor this `bc`: 395*5a6e8488SAndroid Build Coastguard Worker 396*5a6e8488SAndroid Build Coastguard Worker``` 397*5a6e8488SAndroid Build Coastguard Workerreal 0.71 398*5a6e8488SAndroid Build Coastguard Workeruser 0.70 399*5a6e8488SAndroid Build Coastguard Workersys 0.00 400*5a6e8488SAndroid Build Coastguard Worker``` 401*5a6e8488SAndroid Build Coastguard Worker 402*5a6e8488SAndroid Build Coastguard Worker### Scripts 403*5a6e8488SAndroid Build Coastguard Worker 404*5a6e8488SAndroid Build Coastguard WorkerThe command for the `../timeconst.bc` script was: 405*5a6e8488SAndroid Build Coastguard Worker 406*5a6e8488SAndroid Build Coastguard Worker``` 407*5a6e8488SAndroid Build Coastguard Workertime -p [bc] ../timeconst.bc > /dev/null 408*5a6e8488SAndroid Build Coastguard Worker``` 409*5a6e8488SAndroid Build Coastguard Worker 410*5a6e8488SAndroid Build Coastguard WorkerFor GNU `bc`: 411*5a6e8488SAndroid Build Coastguard Worker 412*5a6e8488SAndroid Build Coastguard Worker``` 413*5a6e8488SAndroid Build Coastguard Workerreal 15.62 414*5a6e8488SAndroid Build Coastguard Workeruser 15.08 415*5a6e8488SAndroid Build Coastguard Workersys 0.53 416*5a6e8488SAndroid Build Coastguard Worker``` 417*5a6e8488SAndroid Build Coastguard Worker 418*5a6e8488SAndroid Build Coastguard WorkerFor this `bc`: 419*5a6e8488SAndroid Build Coastguard Worker 420*5a6e8488SAndroid Build Coastguard Worker``` 421*5a6e8488SAndroid Build Coastguard Workerreal 10.09 422*5a6e8488SAndroid Build Coastguard Workeruser 10.08 423*5a6e8488SAndroid Build Coastguard Workersys 0.01 424*5a6e8488SAndroid Build Coastguard Worker``` 425*5a6e8488SAndroid Build Coastguard Worker 426*5a6e8488SAndroid Build Coastguard WorkerThe command for the next script, the `for` loop script, was: 427*5a6e8488SAndroid Build Coastguard Worker 428*5a6e8488SAndroid Build Coastguard Worker``` 429*5a6e8488SAndroid Build Coastguard Workertime -p [bc] ../test.bc > /dev/null 430*5a6e8488SAndroid Build Coastguard Worker``` 431*5a6e8488SAndroid Build Coastguard Worker 432*5a6e8488SAndroid Build Coastguard WorkerFor GNU `bc`: 433*5a6e8488SAndroid Build Coastguard Worker 434*5a6e8488SAndroid Build Coastguard Worker``` 435*5a6e8488SAndroid Build Coastguard Workerreal 14.76 436*5a6e8488SAndroid Build Coastguard Workeruser 14.75 437*5a6e8488SAndroid Build Coastguard Workersys 0.00 438*5a6e8488SAndroid Build Coastguard Worker``` 439*5a6e8488SAndroid Build Coastguard Worker 440*5a6e8488SAndroid Build Coastguard WorkerFor this `bc`: 441*5a6e8488SAndroid Build Coastguard Worker 442*5a6e8488SAndroid Build Coastguard Worker``` 443*5a6e8488SAndroid Build Coastguard Workerreal 17.95 444*5a6e8488SAndroid Build Coastguard Workeruser 17.94 445*5a6e8488SAndroid Build Coastguard Workersys 0.00 446*5a6e8488SAndroid Build Coastguard Worker``` 447*5a6e8488SAndroid Build Coastguard Worker 448*5a6e8488SAndroid Build Coastguard WorkerThe command for the next script, the `while` loop script, was: 449*5a6e8488SAndroid Build Coastguard Worker 450*5a6e8488SAndroid Build Coastguard Worker``` 451*5a6e8488SAndroid Build Coastguard Workertime -p [bc] ../test2.bc > /dev/null 452*5a6e8488SAndroid Build Coastguard Worker``` 453*5a6e8488SAndroid Build Coastguard Worker 454*5a6e8488SAndroid Build Coastguard WorkerFor GNU `bc`: 455*5a6e8488SAndroid Build Coastguard Worker 456*5a6e8488SAndroid Build Coastguard Worker``` 457*5a6e8488SAndroid Build Coastguard Workerreal 14.84 458*5a6e8488SAndroid Build Coastguard Workeruser 14.83 459*5a6e8488SAndroid Build Coastguard Workersys 0.00 460*5a6e8488SAndroid Build Coastguard Worker``` 461*5a6e8488SAndroid Build Coastguard Worker 462*5a6e8488SAndroid Build Coastguard WorkerFor this `bc`: 463*5a6e8488SAndroid Build Coastguard Worker 464*5a6e8488SAndroid Build Coastguard Worker``` 465*5a6e8488SAndroid Build Coastguard Workerreal 13.53 466*5a6e8488SAndroid Build Coastguard Workeruser 13.52 467*5a6e8488SAndroid Build Coastguard Workersys 0.00 468*5a6e8488SAndroid Build Coastguard Worker``` 469*5a6e8488SAndroid Build Coastguard Worker 470*5a6e8488SAndroid Build Coastguard Worker## Link-Time Optimization Only 471*5a6e8488SAndroid Build Coastguard Worker 472*5a6e8488SAndroid Build Coastguard WorkerJust for kicks, let's see if `-march=native` is even useful. 473*5a6e8488SAndroid Build Coastguard Worker 474*5a6e8488SAndroid Build Coastguard WorkerThe optimizations I used for both `bc`'s were `-O3 -flto`. 475*5a6e8488SAndroid Build Coastguard Worker 476*5a6e8488SAndroid Build Coastguard Worker### Addition 477*5a6e8488SAndroid Build Coastguard Worker 478*5a6e8488SAndroid Build Coastguard WorkerThe command used was: 479*5a6e8488SAndroid Build Coastguard Worker 480*5a6e8488SAndroid Build Coastguard Worker``` 481*5a6e8488SAndroid Build Coastguard Workertests/script.sh bc add.bc 1 0 1 1 [bc] 482*5a6e8488SAndroid Build Coastguard Worker``` 483*5a6e8488SAndroid Build Coastguard Worker 484*5a6e8488SAndroid Build Coastguard WorkerFor GNU `bc`: 485*5a6e8488SAndroid Build Coastguard Worker 486*5a6e8488SAndroid Build Coastguard Worker``` 487*5a6e8488SAndroid Build Coastguard Workerreal 2.41 488*5a6e8488SAndroid Build Coastguard Workeruser 1.05 489*5a6e8488SAndroid Build Coastguard Workersys 1.35 490*5a6e8488SAndroid Build Coastguard Worker``` 491*5a6e8488SAndroid Build Coastguard Worker 492*5a6e8488SAndroid Build Coastguard WorkerFor this `bc`: 493*5a6e8488SAndroid Build Coastguard Worker 494*5a6e8488SAndroid Build Coastguard Worker``` 495*5a6e8488SAndroid Build Coastguard Workerreal 0.58 496*5a6e8488SAndroid Build Coastguard Workeruser 0.52 497*5a6e8488SAndroid Build Coastguard Workersys 0.05 498*5a6e8488SAndroid Build Coastguard Worker``` 499*5a6e8488SAndroid Build Coastguard Worker 500*5a6e8488SAndroid Build Coastguard Worker### Subtraction 501*5a6e8488SAndroid Build Coastguard Worker 502*5a6e8488SAndroid Build Coastguard WorkerThe command used was: 503*5a6e8488SAndroid Build Coastguard Worker 504*5a6e8488SAndroid Build Coastguard Worker``` 505*5a6e8488SAndroid Build Coastguard Workertests/script.sh bc subtract.bc 1 0 1 1 [bc] 506*5a6e8488SAndroid Build Coastguard Worker``` 507*5a6e8488SAndroid Build Coastguard Worker 508*5a6e8488SAndroid Build Coastguard WorkerFor GNU `bc`: 509*5a6e8488SAndroid Build Coastguard Worker 510*5a6e8488SAndroid Build Coastguard Worker``` 511*5a6e8488SAndroid Build Coastguard Workerreal 2.39 512*5a6e8488SAndroid Build Coastguard Workeruser 1.10 513*5a6e8488SAndroid Build Coastguard Workersys 1.28 514*5a6e8488SAndroid Build Coastguard Worker``` 515*5a6e8488SAndroid Build Coastguard Worker 516*5a6e8488SAndroid Build Coastguard WorkerFor this `bc`: 517*5a6e8488SAndroid Build Coastguard Worker 518*5a6e8488SAndroid Build Coastguard Worker``` 519*5a6e8488SAndroid Build Coastguard Workerreal 0.65 520*5a6e8488SAndroid Build Coastguard Workeruser 0.57 521*5a6e8488SAndroid Build Coastguard Workersys 0.07 522*5a6e8488SAndroid Build Coastguard Worker``` 523*5a6e8488SAndroid Build Coastguard Worker 524*5a6e8488SAndroid Build Coastguard Worker### Multiplication 525*5a6e8488SAndroid Build Coastguard Worker 526*5a6e8488SAndroid Build Coastguard WorkerThe command used was: 527*5a6e8488SAndroid Build Coastguard Worker 528*5a6e8488SAndroid Build Coastguard Worker``` 529*5a6e8488SAndroid Build Coastguard Workertests/script.sh bc multiply.bc 1 0 1 1 [bc] 530*5a6e8488SAndroid Build Coastguard Worker``` 531*5a6e8488SAndroid Build Coastguard Worker 532*5a6e8488SAndroid Build Coastguard WorkerFor GNU `bc`: 533*5a6e8488SAndroid Build Coastguard Worker 534*5a6e8488SAndroid Build Coastguard Worker``` 535*5a6e8488SAndroid Build Coastguard Workerreal 6.82 536*5a6e8488SAndroid Build Coastguard Workeruser 4.30 537*5a6e8488SAndroid Build Coastguard Workersys 2.51 538*5a6e8488SAndroid Build Coastguard Worker``` 539*5a6e8488SAndroid Build Coastguard Worker 540*5a6e8488SAndroid Build Coastguard WorkerFor this `bc`: 541*5a6e8488SAndroid Build Coastguard Worker 542*5a6e8488SAndroid Build Coastguard Worker``` 543*5a6e8488SAndroid Build Coastguard Workerreal 1.57 544*5a6e8488SAndroid Build Coastguard Workeruser 1.49 545*5a6e8488SAndroid Build Coastguard Workersys 0.08 546*5a6e8488SAndroid Build Coastguard Worker``` 547*5a6e8488SAndroid Build Coastguard Worker 548*5a6e8488SAndroid Build Coastguard Worker### Division 549*5a6e8488SAndroid Build Coastguard Worker 550*5a6e8488SAndroid Build Coastguard WorkerThe command used was: 551*5a6e8488SAndroid Build Coastguard Worker 552*5a6e8488SAndroid Build Coastguard Worker``` 553*5a6e8488SAndroid Build Coastguard Workertests/script.sh bc divide.bc 1 0 1 1 [bc] 554*5a6e8488SAndroid Build Coastguard Worker``` 555*5a6e8488SAndroid Build Coastguard Worker 556*5a6e8488SAndroid Build Coastguard WorkerFor GNU `bc`: 557*5a6e8488SAndroid Build Coastguard Worker 558*5a6e8488SAndroid Build Coastguard Worker``` 559*5a6e8488SAndroid Build Coastguard Workerreal 3.25 560*5a6e8488SAndroid Build Coastguard Workeruser 1.81 561*5a6e8488SAndroid Build Coastguard Workersys 1.43 562*5a6e8488SAndroid Build Coastguard Worker``` 563*5a6e8488SAndroid Build Coastguard Worker 564*5a6e8488SAndroid Build Coastguard WorkerFor this `bc`: 565*5a6e8488SAndroid Build Coastguard Worker 566*5a6e8488SAndroid Build Coastguard Worker``` 567*5a6e8488SAndroid Build Coastguard Workerreal 1.27 568*5a6e8488SAndroid Build Coastguard Workeruser 1.23 569*5a6e8488SAndroid Build Coastguard Workersys 0.04 570*5a6e8488SAndroid Build Coastguard Worker``` 571*5a6e8488SAndroid Build Coastguard Worker 572*5a6e8488SAndroid Build Coastguard Worker### Power 573*5a6e8488SAndroid Build Coastguard Worker 574*5a6e8488SAndroid Build Coastguard WorkerThe command used was: 575*5a6e8488SAndroid Build Coastguard Worker 576*5a6e8488SAndroid Build Coastguard Worker``` 577*5a6e8488SAndroid Build Coastguard Workerprintf '1234567890^100000; halt\n' | time -p [bc] -q > /dev/null 578*5a6e8488SAndroid Build Coastguard Worker``` 579*5a6e8488SAndroid Build Coastguard Worker 580*5a6e8488SAndroid Build Coastguard WorkerFor GNU `bc`: 581*5a6e8488SAndroid Build Coastguard Worker 582*5a6e8488SAndroid Build Coastguard Worker``` 583*5a6e8488SAndroid Build Coastguard Workerreal 10.50 584*5a6e8488SAndroid Build Coastguard Workeruser 10.49 585*5a6e8488SAndroid Build Coastguard Workersys 0.00 586*5a6e8488SAndroid Build Coastguard Worker``` 587*5a6e8488SAndroid Build Coastguard Worker 588*5a6e8488SAndroid Build Coastguard WorkerFor this `bc`: 589*5a6e8488SAndroid Build Coastguard Worker 590*5a6e8488SAndroid Build Coastguard Worker``` 591*5a6e8488SAndroid Build Coastguard Workerreal 0.72 592*5a6e8488SAndroid Build Coastguard Workeruser 0.71 593*5a6e8488SAndroid Build Coastguard Workersys 0.00 594*5a6e8488SAndroid Build Coastguard Worker``` 595*5a6e8488SAndroid Build Coastguard Worker 596*5a6e8488SAndroid Build Coastguard Worker### Scripts 597*5a6e8488SAndroid Build Coastguard Worker 598*5a6e8488SAndroid Build Coastguard WorkerThe command for the `../timeconst.bc` script was: 599*5a6e8488SAndroid Build Coastguard Worker 600*5a6e8488SAndroid Build Coastguard Worker``` 601*5a6e8488SAndroid Build Coastguard Workertime -p [bc] ../timeconst.bc > /dev/null 602*5a6e8488SAndroid Build Coastguard Worker``` 603*5a6e8488SAndroid Build Coastguard Worker 604*5a6e8488SAndroid Build Coastguard WorkerFor GNU `bc`: 605*5a6e8488SAndroid Build Coastguard Worker 606*5a6e8488SAndroid Build Coastguard Worker``` 607*5a6e8488SAndroid Build Coastguard Workerreal 15.50 608*5a6e8488SAndroid Build Coastguard Workeruser 14.81 609*5a6e8488SAndroid Build Coastguard Workersys 0.68 610*5a6e8488SAndroid Build Coastguard Worker``` 611*5a6e8488SAndroid Build Coastguard Worker 612*5a6e8488SAndroid Build Coastguard WorkerFor this `bc`: 613*5a6e8488SAndroid Build Coastguard Worker 614*5a6e8488SAndroid Build Coastguard Worker``` 615*5a6e8488SAndroid Build Coastguard Workerreal 10.17 616*5a6e8488SAndroid Build Coastguard Workeruser 10.15 617*5a6e8488SAndroid Build Coastguard Workersys 0.01 618*5a6e8488SAndroid Build Coastguard Worker``` 619*5a6e8488SAndroid Build Coastguard Worker 620*5a6e8488SAndroid Build Coastguard WorkerThe command for the next script, the `for` loop script, was: 621*5a6e8488SAndroid Build Coastguard Worker 622*5a6e8488SAndroid Build Coastguard Worker``` 623*5a6e8488SAndroid Build Coastguard Workertime -p [bc] ../test.bc > /dev/null 624*5a6e8488SAndroid Build Coastguard Worker``` 625*5a6e8488SAndroid Build Coastguard Worker 626*5a6e8488SAndroid Build Coastguard WorkerFor GNU `bc`: 627*5a6e8488SAndroid Build Coastguard Worker 628*5a6e8488SAndroid Build Coastguard Worker``` 629*5a6e8488SAndroid Build Coastguard Workerreal 14.99 630*5a6e8488SAndroid Build Coastguard Workeruser 14.99 631*5a6e8488SAndroid Build Coastguard Workersys 0.00 632*5a6e8488SAndroid Build Coastguard Worker``` 633*5a6e8488SAndroid Build Coastguard Worker 634*5a6e8488SAndroid Build Coastguard WorkerFor this `bc`: 635*5a6e8488SAndroid Build Coastguard Worker 636*5a6e8488SAndroid Build Coastguard Worker``` 637*5a6e8488SAndroid Build Coastguard Workerreal 16.85 638*5a6e8488SAndroid Build Coastguard Workeruser 16.84 639*5a6e8488SAndroid Build Coastguard Workersys 0.00 640*5a6e8488SAndroid Build Coastguard Worker``` 641*5a6e8488SAndroid Build Coastguard Worker 642*5a6e8488SAndroid Build Coastguard WorkerThe command for the next script, the `while` loop script, was: 643*5a6e8488SAndroid Build Coastguard Worker 644*5a6e8488SAndroid Build Coastguard Worker``` 645*5a6e8488SAndroid Build Coastguard Workertime -p [bc] ../test2.bc > /dev/null 646*5a6e8488SAndroid Build Coastguard Worker``` 647*5a6e8488SAndroid Build Coastguard Worker 648*5a6e8488SAndroid Build Coastguard WorkerFor GNU `bc`: 649*5a6e8488SAndroid Build Coastguard Worker 650*5a6e8488SAndroid Build Coastguard Worker``` 651*5a6e8488SAndroid Build Coastguard Workerreal 14.92 652*5a6e8488SAndroid Build Coastguard Workeruser 14.91 653*5a6e8488SAndroid Build Coastguard Workersys 0.00 654*5a6e8488SAndroid Build Coastguard Worker``` 655*5a6e8488SAndroid Build Coastguard Worker 656*5a6e8488SAndroid Build Coastguard WorkerFor this `bc`: 657*5a6e8488SAndroid Build Coastguard Worker 658*5a6e8488SAndroid Build Coastguard Worker``` 659*5a6e8488SAndroid Build Coastguard Workerreal 12.75 660*5a6e8488SAndroid Build Coastguard Workeruser 12.75 661*5a6e8488SAndroid Build Coastguard Workersys 0.00 662*5a6e8488SAndroid Build Coastguard Worker``` 663*5a6e8488SAndroid Build Coastguard Worker 664*5a6e8488SAndroid Build Coastguard WorkerIt turns out that `-march=native` can be a problem. As such, I have removed the 665*5a6e8488SAndroid Build Coastguard Workerrecommendation to build with `-march=native`. 666*5a6e8488SAndroid Build Coastguard Worker 667*5a6e8488SAndroid Build Coastguard Worker## Recommended Compiler 668*5a6e8488SAndroid Build Coastguard Worker 669*5a6e8488SAndroid Build Coastguard WorkerWhen I ran these benchmarks with my `bc` compiled under `clang` vs. `gcc`, it 670*5a6e8488SAndroid Build Coastguard Workerperformed much better under `clang`. I recommend compiling this `bc` with 671*5a6e8488SAndroid Build Coastguard Worker`clang`. 672*5a6e8488SAndroid Build Coastguard Worker 673*5a6e8488SAndroid Build Coastguard Worker[1]: https://github.com/torvalds/linux/blob/master/kernel/time/timeconst.bc 674