Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 971955fc authored by Anton Ivanov's avatar Anton Ivanov Committed by Android (Google) Code Review
Browse files

Merge "LocklessQueue_benchmarks improvements." into main

parents d1b0cbd7 c8036836
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -10,9 +10,9 @@ package {
cc_benchmark {
    name: "surfaceflinger_microbenchmarks",
    srcs: [
        "*.cpp",
        ":libsurfaceflinger_mock_sources",
        ":libsurfaceflinger_sources",
        "*.cpp",
    ],
    defaults: [
        "libsurfaceflinger_mocks_defaults",
@@ -28,3 +28,15 @@ cc_benchmark {
        "surfaceflinger_tests_common_headers",
    ],
}

cc_benchmark {
    name: "surfaceflinger_microbenchmarks_host_supported",
    srcs: [
        "LocklessQueue_benchmarks.cpp",
        "main.cpp",
    ],
    static_libs: [
        "libgtest",
    ],
    host_supported: true,
}
+1 −0
Original line number Diff line number Diff line
../../LocklessQueue.h
 No newline at end of file
+10 −6
Original line number Diff line number Diff line
@@ -14,8 +14,9 @@
 * limitations under the License.
 */

#include <memory>
#include <optional>
#include <utility>
#include <vector>

#include <benchmark/benchmark.h>

@@ -24,15 +25,18 @@
namespace android::surfaceflinger {

namespace {

static void pushPop(benchmark::State& state) {
    LocklessQueue<std::vector<uint32_t>> queue;
    using ItemT = std::vector<int64_t>;
    LocklessQueue<ItemT> queue;
    ItemT item(size_t(state.range(0)), 42);
    for (auto _ : state) {
        queue.push({10, 5});
        std::vector<uint32_t> poppedValue = *queue.pop();
        benchmark::DoNotOptimize(poppedValue);
        queue.push(std::move(item));
        item = std::move(*queue.pop());
        benchmark::DoNotOptimize(item);
    }
}
BENCHMARK(pushPop);
BENCHMARK(pushPop)->Range(1, 1048576);

} // namespace
} // namespace android::surfaceflinger