MCPcopy Create free account
hub / github.com/apache/arrow / RandomPath

Function RandomPath

cpp/src/arrow/util/machine_benchmark.cc:36–53  ·  view source on GitHub ↗

Generate a vector of indices such as following the indices describes a path over the whole vector. The path is randomized to avoid triggering automatic prefetching in the CPU.

Source from the content-addressed store, hash-verified

34// a path over the whole vector. The path is randomized to avoid triggering
35// automatic prefetching in the CPU.
36std::vector<int32_t> RandomPath(int32_t size) {
37 std::default_random_engine gen(42);
38 std::vector<int32_t> indices(size);
39
40 for (int32_t i = 0; i < size; ++i) {
41 indices[i] = i;
42 }
43 std::shuffle(indices.begin(), indices.end(), gen);
44 std::vector<int32_t> path(size, -999999);
45 int32_t prev;
46 prev = indices[size - 1];
47 for (int32_t i = 0; i < size; ++i) {
48 int32_t next = indices[i];
49 path[prev] = next;
50 prev = next;
51 }
52 return path;
53}
54
55// Cache / main memory latency, depending on the working set size
56static void memory_latency(benchmark::State& state) {

Callers 1

memory_latencyFunction · 0.85

Calls 2

beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected