17 #include "my_config.h"
18 #include <gtest/gtest.h>
20 #include "my_global.h"
25 namespace alignment_unittest {
35 static const int num_iterations= 1;
36 static const int num_records= 100 * 1000;
38 static int* aligned_data;
39 static uchar* unaligned_data;
41 static void SetUpTestCase()
43 aligned_data=
new int[num_records];
44 unaligned_data=
new uchar[(num_records + 1) *
sizeof(
int)];
45 for (
int ix= 0; ix < num_records; ++ix)
47 aligned_data[ix]= ix / 10;
49 std::random_shuffle(aligned_data, aligned_data + num_records);
50 memcpy(unaligned_data + 1, aligned_data, num_records *
sizeof(
int));
53 static void TearDownTestCase()
55 delete[] aligned_data;
56 delete[] unaligned_data;
61 aligned_keys=
new uchar* [num_records];
62 unaligned_keys=
new uchar* [num_records];
63 for (
int ix= 0; ix < num_records; ++ix)
66 static_cast<uchar*
>(
static_cast<void*
>(&aligned_data[ix]));
68 &unaligned_data[1 + (ix *
sizeof(int))];
72 virtual void TearDown()
74 delete[] aligned_keys;
75 delete[] unaligned_keys;
79 uchar **unaligned_keys;
82 int* AlignmentTest::aligned_data;
83 uchar* AlignmentTest::unaligned_data;
86 #define sint4korrgeneric(A) (int32) (((int32) ((uchar) (A)[0])) +\
87 (((int32) ((uchar) (A)[1]) << 8)) + \
88 (((int32) ((uchar) (A)[2]) << 16)) + \
89 (((int32) ((int16) (A)[3]) << 24)))
91 public std::binary_function<const uchar*, const uchar*, bool>
94 bool operator() (
const uchar *s1,
const uchar *s2)
96 return *(
int*) s1 < *(
int*) s2;
101 public std::binary_function<const uchar*, const uchar*, bool>
104 bool operator() (
const uchar *s1,
const uchar *s2)
106 return sint4korr(s1) < sint4korr(s2);
111 public std::binary_function<const uchar*, const uchar*, bool>
114 bool operator() (
const uchar *s1,
const uchar *s2)
116 return sint4korrgeneric(s1) < sint4korrgeneric(s2);
120 #if defined(__i386__) || defined(__x86_64__) || defined(__WIN__)
125 for (
int ix= 0; ix < num_iterations; ++ix)
127 std::vector<uchar*> keys(aligned_keys, aligned_keys + num_records);
132 TEST_F(AlignmentTest, UnAlignedSort)
134 for (
int ix= 0; ix < num_iterations; ++ix)
136 std::vector<uchar*> keys(unaligned_keys, unaligned_keys + num_records);
137 std::sort(keys.begin(), keys.end(), Mem_compare_uchar_int());
141 TEST_F(AlignmentTest, Sint4Sort)
143 for (
int ix= 0; ix < num_iterations; ++ix)
145 std::vector<uchar*> keys(unaligned_keys, unaligned_keys + num_records);
146 std::sort(keys.begin(), keys.end(), Mem_compare_sint4());
150 TEST_F(AlignmentTest, Sint4SortGeneric)
152 for (
int ix= 0; ix < num_iterations; ++ix)
154 std::vector<uchar*> keys(unaligned_keys, unaligned_keys + num_records);
155 std::sort(keys.begin(), keys.end(), Mem_compare_sint4_generic());