[libcxx-commits] [libcxx] [libc++] Vectorize mismatch (PR #73255)

Denis Yaroshevskiy via libcxx-commits libcxx-commits at lists.llvm.org
Sat Feb 24 08:45:08 PST 2024


================
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include <algorithm>
+#include <benchmark/benchmark.h>
+#include <random>
+
+template <class T>
+static void bm_mismatch(benchmark::State& state) {
+  std::vector<T> vec1(state.range(), '1');
+  std::vector<T> vec2(state.range(), '1');
+  std::mt19937_64 rng(std::random_device{}());
+
+  for (auto _ : state) {
+    auto idx  = rng() % vec1.size();
----------------
DenisYaroshevskiy wrote:

This is weird for a benchmark.

benchmark should always do the same: the whole measuring system relies on that, it will try to do the "avarage" between the iteration.

If you want to measure for different positions - do a few becnhmarks with different offsets.

I wouldn't bother though, just pick last element for mistmatch or smth.

https://github.com/llvm/llvm-project/pull/73255


More information about the libcxx-commits mailing list