25 using namespace impala;
28 int StringCompare1(
const char* s1,
int n1,
const char* s2,
int n2,
int len) {
29 DCHECK_EQ(len, std::min(n1, n2));
32 __m128i xmm0 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(s1));
33 __m128i xmm1 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(s2));
37 return s1[chars_match] - s2[chars_match];
45 __m128i xmm0 = _mm_loadl_epi64(reinterpret_cast<const __m128i*>(s1));
46 __m128i xmm1 = _mm_loadl_epi64(reinterpret_cast<const __m128i*>(s2));
52 return s1[chars_match] - s2[chars_match];
60 int result = strncmp(s1, s2, len);
61 if (result != 0)
return result;
66 int StringCompare2(
const char* s1,
int n1,
const char* s2,
int n2,
int len) {
67 DCHECK_EQ(len, std::min(n1, n2));
70 __m128i xmm0 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(s1));
71 __m128i xmm1 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(s2));
72 int n = std::min(len, 16);
75 return s1[chars_match] - s2[chars_match];
84 int result = strncmp(s1, s2, len);
85 if (result != 0)
return result;
90 int StringCompare3(
const char* s1,
int n1,
const char* s2,
int n2,
int len) {
91 DCHECK_EQ(len, std::min(n1, n2));
94 __m128i xmm0 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(s1));
95 __m128i xmm1 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(s2));
99 return s1[chars_match] - s2[chars_match];
107 int result = strncmp(s1, s2, len);
108 if (result != 0)
return result;
122 int len = std::min(data->
n1, data->
n2);
123 for (
int i = 0; i < batch_size; ++i) {
138 int len = std::min(data->
n1, data->
n2);
139 for (
int i = 0; i < batch_size; ++i) {
154 int len = std::min(data->
n1, data->
n2);
155 for (
int i = 0; i < batch_size; ++i) {
170 data.
s1 =
new char[len];
171 data.
s2 =
new char[len];
172 data.
n1 = data.
n2 = len;
173 for (
int i = 0; i < len; ++i) {
174 data.
s1[i] = data.
s2[i] =
'a';
179 int main(
int argc,
char **argv) {
182 Benchmark long_suite(
"Long strings (10000)");
189 Benchmark med_suite(
"Med strings (100)");
196 Benchmark short_suite(
"Short strings (10)");
int AddBenchmark(const std::string &name, BenchmarkFunction fn, void *args, int baseline_idx=0)
void TestStringCompare3(int batch_size, void *d)
int StringCompare1(const char *s1, int n1, const char *s2, int n2, int len)
int StringCompare3(const char *s1, int n1, const char *s2, int n2, int len)
void TestStringCompare2(int batch_size, void *d)
static SSE_ALWAYS_INLINE int SSE4_cmpestri(__m128i str1, int len1, __m128i str2, int len2, const int mode)
std::string Measure()
Runs all the benchmarks and returns the result in a formatted string.
TestData InitTestData(int len)
static const int64_t SSE4_2
void TestStringCompare1(int batch_size, void *d)
int main(int argc, char **argv)
int StringCompare2(const char *s1, int n1, const char *s2, int n2, int len)
static const int STRCMP_MODE
static const int CHARS_PER_64_BIT_REGISTER
static void Init()
Initialize CpuInfo.
static bool IsSupported(long flag)
Returns whether of not the cpu supports this flag.
static const int CHARS_PER_128_BIT_REGISTER