1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
// Copyright (c) 2021-2024, Intel Corporation
// SPDX-License-Identifier: BSD-3-Clause
#include <benchmark/benchmark.h>
#include <cmath>
#include <stdio.h>
#include "../common.h"
#include "test01_ispc.h"
WARM_UP_RUN();
const float eps = 0.00001f;
#define ARGS Arg(100)->Arg(1000)->Arg(10000)
using namespace ispc;
static void init(struct FVector *dst, struct FVector *src0, struct FVector *src1, int count) {
for (int i = 0; i < count; i++) {
src0[i].V[0] = (float)i;
src0[i].V[1] = (float)(i + 1);
src0[i].V[2] = (float)(i + 2);
src1[i].V[0] = 2;
src1[i].V[1] = 4;
src1[i].V[2] = 8;
dst[i].V[0] = 0;
dst[i].V[1] = 0;
dst[i].V[2] = 0;
}
}
static void check(struct FVector *dst, struct FVector *src0, struct FVector *src1, int count) {
for (int i = 0; i < count; i++) {
for (int j = 0; j < 3; j++) {
if (std::abs(dst[i].V[j] - src0[i].V[j] * src1[i].V[j]) > eps) {
printf("Error i=%d\n", i);
return;
}
}
}
}
static void test01_1(benchmark::State &state) {
int count = static_cast<int>(state.range(0));
FVector *src0 = new FVector[count];
FVector *src1 = new FVector[count];
FVector *dst = new FVector[count];
init(dst, src0, src1, count);
for (auto _ : state) {
TestUniform1(dst, src0, src1, count);
}
check(dst, src0, src1, count);
delete[] src0;
delete[] src1;
delete[] dst;
}
BENCHMARK(test01_1)->ARGS;
static void test01_2(benchmark::State &state) {
int count = static_cast<int>(state.range(0));
FVector *src0 = new FVector[count];
FVector *src1 = new FVector[count];
FVector *dst = new FVector[count];
init(dst, src0, src1, count);
for (auto _ : state) {
TestUniform2(dst, src0, src1, count);
}
check(dst, src0, src1, count);
delete[] src0;
delete[] src1;
delete[] dst;
}
BENCHMARK(test01_2)->ARGS;
static void test01_3(benchmark::State &state) {
int count = static_cast<int>(state.range(0));
FVector *src0 = new FVector[count];
FVector *src1 = new FVector[count];
FVector *dst = new FVector[count];
init(dst, src0, src1, count);
for (auto _ : state) {
TestUniform3(dst, src0, src1, count);
}
check(dst, src0, src1, count);
delete[] src0;
delete[] src1;
delete[] dst;
}
BENCHMARK(test01_3)->ARGS;
BENCHMARK_MAIN();
|