/* * Copyright 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include #include #include /* Pixel 7 (USE_NEON code) 1024 frames ------------------------------------------------------------------------------------ Benchmark Time CPU Iteration ------------------------------------------------------------------------------------ audio_power_benchmark: #BM_Power_PCM16/0 180.92289679585028 ns 180.15104399245882 ns 3885325 #BM_Power_PCM16/1 181.16126874965656 ns 180.28731034748992 ns 3885725 #BM_Power_PCM16/2 366.9960881450727 ns 365.39403294327775 ns 1916992 #BM_Power_PCM16/3 548.5112717240582 ns 546.0744994668512 ns 1124451 #BM_Power_PCM16/4 729.0495355718209 ns 725.8359358395215 ns 964519 #BM_Power_PCM16/5 730.510620314316 ns 726.6058324908629 ns 964425 #BM_Power_PCM16/6 728.7902308009492 ns 725.5839959346857 ns 964255 #BM_Power_PCM16/7 728.9437536542266 ns 725.7622692705022 ns 964116 #BM_Power_PCM16/8 909.5644815487676 ns 905.2594277274385 ns 773198 #BM_Power_PCM16/9 909.8487590417226 ns 905.541972865661 ns 773190 #BM_Power_PCM16/10 909.183445722452 ns 905.3521771357088 ns 773057 #BM_Power_PCM16/11 1090.09789477985 ns 1085.3346029826685 ns 645060 #BM_Power_PCM16/12 1090.3917184788897 ns 1085.1526904891118 ns 645050 #BM_Power_PCM16/13 1090.6139456707829 ns 1085.3129791109552 ns 645075 #BM_Power_PCM16/14 1270.3910705694595 ns 1264.6607241907009 ns 553473 #BM_Power_PCM16/15 1451.2089754139336 ns 1444.6507448881837 ns 484368 #BM_Power_PCM16/16 1450.9700749658366 ns 1444.8052807460408 ns 484477 #BM_Power_PCM16/17 1812.303903144669 ns 1803.980427679052 ns 388048 #BM_Power_PCM16/18 1811.9722496408933 ns 1804.060838412867 ns 387995 #BM_Power_PCM16/19 2172.9285815784997 ns 2163.549761392581 ns 323544 #BM_Power_PCM16/20 2895.717365719501 ns 2882.4285590756745 ns 242858 #BM_Power_PCM16/21 2362.8065810160383 ns 2343.214059957551 ns 298678 #BM_Power_PCM16/22 4375.607432531217 ns 4349.7750805466185 ns 162018 #BM_Power_PCM24/0 729.5894710558571 ns 726.1363670792448 ns 963781 #BM_Power_PCM24/1 729.3882670878899 ns 726.1209068088475 ns 964040 #BM_Power_PCM24/2 1458.6373129782264 ns 1451.9195964682701 ns 482143 #BM_Power_PCM24/3 2187.9754265826004 ns 2177.8859773833788 ns 321445 #BM_Power_PCM24/4 2916.471421225014 ns 2903.4799741173238 ns 241088 #BM_Power_PCM24/5 2916.8920647399905 ns 2903.440625661062 ns 241089 #BM_Power_PCM24/6 2917.0361012229073 ns 2903.434031522186 ns 241100 #BM_Power_PCM24/7 2917.120625640503 ns 2903.6405370541643 ns 241093 #BM_Power_PCM24/8 3646.476550238203 ns 3629.390335960183 ns 192880 #BM_Power_PCM24/9 3645.840301799253 ns 3629.2467050344903 ns 192870 #BM_Power_PCM24/10 3644.269759390758 ns 3629.3227967213143 ns 192883 #BM_Power_PCM24/11 4380.128164445656 ns 4354.962614554768 ns 160731 #BM_Power_PCM24/12 4388.973117427308 ns 4354.930644037431 ns 160736 #BM_Power_PCM24/13 4374.525575418697 ns 4354.927302592676 ns 160721 #BM_Power_PCM24/14 5118.992190017827 ns 5087.803814971004 ns 137773 #BM_Power_PCM24/15 5834.08466279494 ns 5806.663514107713 ns 120537 #BM_Power_PCM24/16 5833.92617600098 ns 5806.763406521383 ns 120557 #BM_Power_PCM24/17 7292.561040415548 ns 7258.959351364824 ns 96387 #BM_Power_PCM24/18 7290.05913892853 ns 7257.935738432544 ns 96434 #BM_Power_PCM24/19 8748.81338349567 ns 8710.19083466056 ns 80368 #BM_Power_PCM24/20 11670.86173811743 ns 11617.8891747444 ns 60248 #BM_Power_PCM24/21 9483.894109345772 ns 9440.172604919655 ns 74152 #BM_Power_PCM24/22 17519.172322663 ns 17440.687347386174 ns 40134 #BM_Power_PCM32/0 180.0209277417017 ns 179.20765234810716 ns 3905677 #BM_Power_PCM32/1 179.9928913935374 ns 179.1684100688871 ns 3906251 #BM_Power_PCM32/2 365.261156361417 ns 363.63974493506385 ns 1925000 #BM_Power_PCM32/3 547.3235281262711 ns 544.8913868960904 ns 1284624 #BM_Power_PCM32/4 729.4047246495911 ns 726.1992527464306 ns 963796 #BM_Power_PCM32/5 729.4026048853057 ns 726.2301922807576 ns 963955 #BM_Power_PCM32/6 729.4836424896052 ns 726.2090315177677 ns 963869 #BM_Power_PCM32/7 729.4162009832139 ns 726.1991190455375 ns 959868 #BM_Power_PCM32/8 912.2165759413726 ns 908.1020182643767 ns 771009 #BM_Power_PCM32/9 912.4562880732158 ns 908.1058311552687 ns 770945 #BM_Power_PCM32/10 913.6662892148578 ns 909.0608019154854 ns 770979 #BM_Power_PCM32/11 1098.264694586373 ns 1092.9951908063122 ns 640440 #BM_Power_PCM32/12 1097.8838885144464 ns 1092.9489029436984 ns 640350 #BM_Power_PCM32/13 1098.1035265039986 ns 1092.978751342772 ns 640464 #BM_Power_PCM32/14 1281.5146387499506 ns 1274.678222409978 ns 549193 #BM_Power_PCM32/15 1462.932101769714 ns 1456.0376080037322 ns 477877 #BM_Power_PCM32/16 1462.1173842383478 ns 1455.9795936297865 ns 478037 #BM_Power_PCM32/17 1826.1988109374897 ns 1818.7870198104167 ns 384848 #BM_Power_PCM32/18 1826.7986165280556 ns 1819.0798595772844 ns 384838 #BM_Power_PCM32/19 2191.3019592411697 ns 2181.655935394193 ns 320838 #BM_Power_PCM32/20 2931.8883516177143 ns 2917.725262082898 ns 239905 #BM_Power_PCM32/21 2379.3091425177577 ns 2368.454290770179 ns 295553 #BM_Power_PCM32/22 4422.450541711959 ns 4403.615219171803 ns 159943 #BM_Power_FLOAT/0 93.18406291611159 ns 92.72058949295965 ns 7553678 #BM_Power_FLOAT/1 92.96117761951658 ns 92.53548505608882 ns 7556054 #BM_Power_FLOAT/2 188.52435343170848 ns 187.6555618949056 ns 3728037 #BM_Power_FLOAT/3 280.48933614094835 ns 279.55113138431284 ns 2504675 #BM_Power_FLOAT/4 368.2923103024517 ns 366.59376988731435 ns 1893481 #BM_Power_FLOAT/5 368.1838437118831 ns 366.5048535862692 ns 1910340 #BM_Power_FLOAT/6 369.36474434357825 ns 367.32105894972386 ns 1909288 #BM_Power_FLOAT/7 368.20110381565314 ns 366.5717728132608 ns 1909372 #BM_Power_FLOAT/8 458.8126480295947 ns 456.74935048246607 ns 1533061 #BM_Power_FLOAT/9 458.29885591662384 ns 456.42679064123894 ns 1533110 #BM_Power_FLOAT/10 458.4213634993639 ns 456.3022994462401 ns 1534065 #BM_Power_FLOAT/11 548.6835275729175 ns 546.1359314624694 ns 1281050 #BM_Power_FLOAT/12 548.5658948648728 ns 546.1222584767767 ns 1281678 #BM_Power_FLOAT/13 549.7411047192542 ns 546.3104058269406 ns 1280398 #BM_Power_FLOAT/14 639.2796692591446 ns 636.3039215508022 ns 1100432 #BM_Power_FLOAT/15 732.6126268814043 ns 728.9874047781268 ns 960126 #BM_Power_FLOAT/16 732.3223255154735 ns 729.0677081868715 ns 960135 #BM_Power_FLOAT/17 912.688931847384 ns 908.6882020903489 ns 770111 #BM_Power_FLOAT/18 912.94823797903 ns 908.767039789369 ns 770256 #BM_Power_FLOAT/19 1093.0075590498282 ns 1088.1831744600092 ns 643070 #BM_Power_FLOAT/20 1463.591460755948 ns 1457.1715864853975 ns 480370 #BM_Power_FLOAT/21 1186.9261155706474 ns 1181.6336976486523 ns 592344 #BM_Power_FLOAT/22 2219.151555923471 ns 2208.8095264975427 ns 318879 Pixel 7 (generic intrinsics) audio_power_benchmark: #BM_Power_PCM16/0 141.39894261206203 ns 140.74631807527237 ns 4973961 #BM_Power_PCM16/1 141.30068134838092 ns 140.673563398614 ns 4974675 #BM_Power_PCM16/2 278.2230465394509 ns 276.91650670645566 ns 2526670 #BM_Power_PCM16/3 416.70229281643674 ns 413.696774806424 ns 1694813 #BM_Power_PCM16/4 551.6619269166048 ns 549.2264481641901 ns 1270039 #BM_Power_PCM16/5 550.4119551187774 ns 548.1631002490425 ns 1276491 #BM_Power_PCM16/6 549.8963120792694 ns 547.3601694915252 ns 1273456 #BM_Power_PCM16/7 551.9152668960979 ns 549.5658038666706 ns 1274378 #BM_Power_PCM16/8 691.2875636182188 ns 687.659654354893 ns 1025387 #BM_Power_PCM16/9 689.7719348428035 ns 683.1671495932702 ns 1017753 #BM_Power_PCM16/10 688.385108618128 ns 685.2313404997149 ns 1021343 #BM_Power_PCM16/11 824.7405061324669 ns 821.3459965179951 ns 851234 #BM_Power_PCM16/12 824.8310788746044 ns 821.1664236259036 ns 854452 #BM_Power_PCM16/13 822.9901445586745 ns 819.2438917777235 ns 857901 #BM_Power_PCM16/14 961.7364426681155 ns 957.7359233226135 ns 731689 #BM_Power_PCM16/15 1060.764876366047 ns 1056.6351267548569 ns 641790 #BM_Power_PCM16/16 1097.4902606840346 ns 1093.1660882847204 ns 640292 #BM_Power_PCM16/17 1371.8822829713993 ns 1366.1015167052424 ns 511965 #BM_Power_PCM16/18 1379.527502464746 ns 1369.2386592623832 ns 512136 #BM_Power_PCM16/19 1642.4514828653857 ns 1635.289426374952 ns 428869 #BM_Power_PCM16/20 2181.5514388801307 ns 2171.463230349669 ns 321216 #BM_Power_PCM16/21 1772.0538271784708 ns 1764.8680693837691 ns 396231 #BM_Power_PCM16/22 3253.2907084319877 ns 3238.3741398011207 ns 219426 #BM_Power_PCM24/0 728.6418691492001 ns 725.3989273888943 ns 964935 #BM_Power_PCM24/1 728.3793964971507 ns 725.3592953992454 ns 964972 #BM_Power_PCM24/2 1457.2141301147049 ns 1450.6804473488357 ns 482487 #BM_Power_PCM24/3 2186.456712541353 ns 2176.054527369373 ns 321710 #BM_Power_PCM24/4 2930.220041861956 ns 2913.4611367827733 ns 241295 #BM_Power_PCM24/5 2914.6065552550235 ns 2901.222598977792 ns 241241 #BM_Power_PCM24/6 2914.4422212238487 ns 2901.1865175244834 ns 241291 #BM_Power_PCM24/7 2914.0364494153173 ns 2901.173080031326 ns 241293 #BM_Power_PCM24/8 3641.242930020149 ns 3626.409360996713 ns 193035 #BM_Power_PCM24/9 3654.4684532440847 ns 3632.299661712377 ns 193031 #BM_Power_PCM24/10 3642.4799922930624 ns 3626.4395211007954 ns 193026 #BM_Power_PCM24/11 4370.161811319268 ns 4351.627426113113 ns 160854 #BM_Power_PCM24/12 4371.614458426819 ns 4351.7940097723185 ns 160862 #BM_Power_PCM24/13 4387.422872492355 ns 4363.170747931368 ns 160857 #BM_Power_PCM24/14 5101.130549812997 ns 5077.108034788132 ns 137863 #BM_Power_PCM24/15 5826.311256536362 ns 5802.145559755925 ns 120624 #BM_Power_PCM24/16 5829.212266562846 ns 5802.334386087034 ns 120636 #BM_Power_PCM24/17 7284.666217547489 ns 7252.658321762346 ns 96506 #BM_Power_PCM24/18 7283.647952825528 ns 7252.640452115548 ns 96524 #BM_Power_PCM24/19 8741.574695279003 ns 8703.302113901984 ns 80420 #BM_Power_PCM24/20 11660.35250035382 ns 11608.754092379155 ns 60295 #BM_Power_PCM24/21 9498.126111783777 ns 9429.283448331573 ns 74204 #BM_Power_PCM24/22 17500.249881617296 ns 17427.527024672003 ns 40167 #BM_Power_PCM32/0 482.2639310164815 ns 480.16807832291283 ns 1457862 #BM_Power_PCM32/1 482.5041888036376 ns 480.17729091453714 ns 1457813 #BM_Power_PCM32/2 970.7658094980881 ns 966.432565916653 ns 724248 #BM_Power_PCM32/3 1470.8525316656937 ns 1453.8102836400858 ns 481561 #BM_Power_PCM32/4 1945.6320264943743 ns 1937.5130371239736 ns 361276 #BM_Power_PCM32/5 1957.2762784111894 ns 1941.2989846816433 ns 361266 #BM_Power_PCM32/6 1947.606134398178 ns 1937.6027027251473 ns 361339 #BM_Power_PCM32/7 1945.564237181621 ns 1937.4354472085072 ns 361185 #BM_Power_PCM32/8 2449.222944697634 ns 2430.0832236340734 ns 288668 #BM_Power_PCM32/9 2447.1957648212733 ns 2429.213497391568 ns 288678 #BM_Power_PCM32/10 2451.5493899925777 ns 2433.2397932673425 ns 288682 #BM_Power_PCM32/11 2918.8149689454144 ns 2907.2442323189375 ns 240738 #BM_Power_PCM32/12 2922.758025449901 ns 2907.4440844806995 ns 240765 #BM_Power_PCM32/13 2920.348076535013 ns 2907.431136456142 ns 240766 #BM_Power_PCM32/14 3409.4233573973634 ns 3392.591268822002 ns 206341 #BM_Power_PCM32/15 3892.2040848068073 ns 3875.2047879260954 ns 180621 #BM_Power_PCM32/16 3892.308491260789 ns 3875.119794723041 ns 180634 #BM_Power_PCM32/17 4888.503959312049 ns 4860.592739616924 ns 144345 #BM_Power_PCM32/18 4873.615265528875 ns 4849.78500253456 ns 144011 #BM_Power_PCM32/19 5845.323708631462 ns 5818.852960983018 ns 120281 #BM_Power_PCM32/20 7797.718549579573 ns 7766.08286177126 ns 90126 #BM_Power_PCM32/21 6337.479234114833 ns 6314.164677589355 ns 111023 #BM_Power_PCM32/22 11808.601733014153 ns 11756.832074866097 ns 59199 #BM_Power_FLOAT/0 94.11062191883384 ns 93.5736954638585 ns 7472407 #BM_Power_FLOAT/1 94.06728569924215 ns 93.63184288806207 ns 7483938 #BM_Power_FLOAT/2 191.0388817303329 ns 190.21414162539318 ns 3681755 #BM_Power_FLOAT/3 276.28209107363284 ns 275.12531375653344 ns 2531023 #BM_Power_FLOAT/4 370.5403080819118 ns 367.7074869536902 ns 1885974 #BM_Power_FLOAT/5 368.4663243042483 ns 366.8448226390385 ns 1909834 #BM_Power_FLOAT/6 368.1926881965903 ns 366.49226689956845 ns 1909842 #BM_Power_FLOAT/7 368.2706570163833 ns 366.7828121257029 ns 1907717 #BM_Power_FLOAT/8 458.03934294857197 ns 456.15671441471744 ns 1534862 #BM_Power_FLOAT/9 458.27552421764045 ns 456.13744029161853 ns 1533495 #BM_Power_FLOAT/10 458.581440769096 ns 456.3724914204393 ns 1533587 #BM_Power_FLOAT/11 551.6756052533791 ns 549.2340707415847 ns 1274102 #BM_Power_FLOAT/12 551.9493186375631 ns 549.5109769458269 ns 1274216 #BM_Power_FLOAT/13 554.0572718262348 ns 550.19352884349 ns 1274239 #BM_Power_FLOAT/14 642.1574617184507 ns 639.3852457219499 ns 1094774 #BM_Power_FLOAT/15 735.7774064797563 ns 732.5321681956469 ns 960001 #BM_Power_FLOAT/16 737.5902914983094 ns 734.2400489412615 ns 950527 #BM_Power_FLOAT/17 911.3091743315161 ns 907.1963370929745 ns 773211 #BM_Power_FLOAT/18 911.1150959691154 ns 907.0670443387347 ns 772981 #BM_Power_FLOAT/19 1090.110913165201 ns 1085.3036540513142 ns 644928 #BM_Power_FLOAT/20 1471.985775109006 ns 1465.513079056131 ns 477825 #BM_Power_FLOAT/21 1195.7143711208662 ns 1190.262823056866 ns 587087 #BM_Power_FLOAT/22 2220.2886873989446 ns 2209.9696500844384 ns 317991 */ static constexpr audio_channel_mask_t kChannelPositionMasks[] = { AUDIO_CHANNEL_OUT_FRONT_LEFT, AUDIO_CHANNEL_OUT_FRONT_CENTER, AUDIO_CHANNEL_OUT_STEREO, AUDIO_CHANNEL_OUT_2POINT1, AUDIO_CHANNEL_OUT_2POINT0POINT2, AUDIO_CHANNEL_OUT_QUAD, // AUDIO_CHANNEL_OUT_QUAD_BACK AUDIO_CHANNEL_OUT_QUAD_SIDE, AUDIO_CHANNEL_OUT_SURROUND, AUDIO_CHANNEL_OUT_2POINT1POINT2, AUDIO_CHANNEL_OUT_3POINT0POINT2, AUDIO_CHANNEL_OUT_PENTA, AUDIO_CHANNEL_OUT_3POINT1POINT2, AUDIO_CHANNEL_OUT_5POINT1, // AUDIO_CHANNEL_OUT_5POINT1_BACK AUDIO_CHANNEL_OUT_5POINT1_SIDE, AUDIO_CHANNEL_OUT_6POINT1, AUDIO_CHANNEL_OUT_5POINT1POINT2, AUDIO_CHANNEL_OUT_7POINT1, AUDIO_CHANNEL_OUT_5POINT1POINT4, AUDIO_CHANNEL_OUT_7POINT1POINT2, AUDIO_CHANNEL_OUT_7POINT1POINT4, AUDIO_CHANNEL_OUT_9POINT1POINT6, AUDIO_CHANNEL_OUT_13POINT_360RA, AUDIO_CHANNEL_OUT_22POINT2, }; template static void BenchmarkPower(benchmark::State& state) { const audio_channel_mask_t channelMask = kChannelPositionMasks[state.range(0)]; const size_t channels = audio_channel_count_from_out_mask(channelMask); // set up random generator. constexpr float amplitude = 0.01f; std::minstd_rand gen(channelMask); std::uniform_real_distribution<> dis(-amplitude, amplitude); // get random audio data. constexpr size_t frameCount = 1024; std::vector input(channels * frameCount); for (auto& in : input) { in = dis(gen); } // convert to proper PCM format. std::vector buffer(channels * frameCount * audio_bytes_per_sample(FORMAT)); memcpy_by_audio_format(buffer.data(), FORMAT, input.data(), AUDIO_FORMAT_PCM_FLOAT, input.size()); // run the test for (auto _ : state) { benchmark::DoNotOptimize(buffer); audio_utils_compute_energy_mono(buffer.data(), FORMAT, input.size()); benchmark::ClobberMemory(); } state.SetComplexityN(channels); state.SetLabel(audio_channel_out_mask_to_string(channelMask)); } static void ChannelArgs(benchmark::internal::Benchmark* b) { for (int i = 0; i < (int)std::size(kChannelPositionMasks); i++) { b->Args({i}); } } static void BM_Power_PCM16(benchmark::State& state) { BenchmarkPower(state); } static void BM_Power_PCM24(benchmark::State& state) { BenchmarkPower(state); } static void BM_Power_PCM32(benchmark::State& state) { BenchmarkPower(state); } static void BM_Power_FLOAT(benchmark::State& state) { BenchmarkPower(state); } BENCHMARK(BM_Power_PCM16)->Apply(ChannelArgs); BENCHMARK(BM_Power_PCM24)->Apply(ChannelArgs); BENCHMARK(BM_Power_PCM32)->Apply(ChannelArgs); BENCHMARK(BM_Power_FLOAT)->Apply(ChannelArgs); BENCHMARK_MAIN();