mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-18 05:32:52 +00:00
Added another method
This commit is contained in:
parent
d94717c699
commit
a7e5feb8b4
@ -71,6 +71,12 @@ struct State
|
||||
count += size;
|
||||
}
|
||||
|
||||
void merge(const State & other)
|
||||
{
|
||||
sum += other.sum;
|
||||
count += other.count;
|
||||
}
|
||||
|
||||
Float result() const
|
||||
{
|
||||
return sum / count;
|
||||
@ -474,6 +480,30 @@ Float NO_INLINE buffered(const PODArray<UInt8> & keys, const PODArray<Float> & v
|
||||
}
|
||||
|
||||
|
||||
template <size_t UNROLL_COUNT>
|
||||
Float NO_INLINE really_unrolled(const PODArray<UInt8> & keys, const PODArray<Float> & values)
|
||||
{
|
||||
State map[256 * UNROLL_COUNT]{};
|
||||
|
||||
size_t size = keys.size();
|
||||
size_t i = 0;
|
||||
|
||||
size_t size_unrolled = size / UNROLL_COUNT * UNROLL_COUNT;
|
||||
for (; i < size_unrolled; i += UNROLL_COUNT)
|
||||
for (size_t j = 0; j < UNROLL_COUNT; ++j)
|
||||
map[256 * j + keys[i + j]].add(values[i + j]);
|
||||
|
||||
for (size_t key = 0; key < 256; ++key)
|
||||
for (size_t j = 1; j < UNROLL_COUNT; ++j)
|
||||
map[key].merge(map[256 * j + key]);
|
||||
|
||||
for (; i < size; ++i)
|
||||
map[keys[i]].add(values[i]);
|
||||
|
||||
return map[0].result();
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
size_t size = argc > 1 ? std::stoull(argv[1]) : 1000000000;
|
||||
@ -486,7 +516,7 @@ int main(int argc, char ** argv)
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
{
|
||||
keys[i] = __builtin_ctz(i + 1); /// Make keys to have just slightly more realistic distribution.
|
||||
values[i] = i; /// The distribution of values does not affect execution speed.
|
||||
values[i] = 1234.5; /// The distribution of values does not affect execution speed.
|
||||
}
|
||||
|
||||
/// Aggregate
|
||||
@ -506,6 +536,7 @@ int main(int argc, char ** argv)
|
||||
case 8: res = microsort<1>(keys, values); break;
|
||||
case 9: res = baseline_baseline(keys, values); break;
|
||||
case 10: res = buffered(keys, values); break;
|
||||
case 11: res = really_unrolled<1>(keys, values); break;
|
||||
|
||||
case 32: res = unrolled<2>(keys, values); break;
|
||||
case 34: res = unrolled<4>(keys, values); break;
|
||||
@ -537,6 +568,12 @@ int main(int argc, char ** argv)
|
||||
case 88: res = microsort<8>(keys, values); break;
|
||||
case 816: res = microsort<16>(keys, values); break;
|
||||
|
||||
case 112: res = really_unrolled<2>(keys, values); break;
|
||||
case 114: res = really_unrolled<4>(keys, values); break;
|
||||
case 116: res = really_unrolled<5>(keys, values); break;
|
||||
case 118: res = really_unrolled<8>(keys, values); break;
|
||||
case 1116: res = really_unrolled<16>(keys, values); break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user