2 * Copyright 2014 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <folly/Benchmark.h>
18 #include <folly/experimental/EliasFanoCoding.h>
19 #include <folly/experimental/test/CodingTestUtils.h>
21 using namespace folly::compression;
23 template <size_t kVersion>
25 static constexpr size_t Version = kVersion;
29 class EliasFanoCodingTest : public ::testing::Test {
32 typedef EliasFanoEncoder<uint32_t, size_t, 0, 0, T::Version> Encoder;
33 typedef EliasFanoReader<Encoder> Reader;
34 testEmpty<Reader, Encoder>();
37 template <size_t kSkipQuantum, size_t kForwardQuantum>
39 typedef EliasFanoEncoder<
40 uint32_t, uint32_t, kSkipQuantum, kForwardQuantum, T::Version> Encoder;
41 typedef EliasFanoReader<Encoder> Reader;
42 testAll<Reader, Encoder>(generateRandomList(100 * 1000, 10 * 1000 * 1000));
43 testAll<Reader, Encoder>(generateSeqList(1, 100000, 100));
47 typedef ::testing::Types<TestType<0>, TestType<1>> TestTypes;
48 TYPED_TEST_CASE(EliasFanoCodingTest, TestTypes);
50 TYPED_TEST(EliasFanoCodingTest, Empty) {
51 TestFixture::doTestEmpty();
54 TYPED_TEST(EliasFanoCodingTest, Simple) {
55 TestFixture::template doTestAll<0, 0>();
58 TYPED_TEST(EliasFanoCodingTest, SkipPointers) {
59 TestFixture::template doTestAll<128, 0>();
62 TYPED_TEST(EliasFanoCodingTest, ForwardPointers) {
63 TestFixture::template doTestAll<0, 128>();
66 TYPED_TEST(EliasFanoCodingTest, SkipForwardPointers) {
67 TestFixture::template doTestAll<128, 128>();
72 constexpr size_t k1M = 1000000;
73 constexpr size_t kVersion = 1;
75 typedef EliasFanoEncoder<uint32_t, uint32_t, 128, 128, kVersion> Encoder;
76 typedef EliasFanoReader<Encoder> Reader;
78 std::vector<uint32_t> data;
79 typename Encoder::CompressedList list;
82 data = generateRandomList(100 * 1000, 10 * 1000 * 1000);
83 //data = loadList("/home/philipp/pl_test_dump.txt");
84 Encoder::encode(data.data(), data.size(), bm::list);
94 bmNext<bm::Reader>(bm::list, bm::data, bm::k1M);
97 BENCHMARK(Skip1_ForwarQ128_1M) {
98 bmSkip<bm::Reader>(bm::list, bm::data, 1, bm::k1M);
101 BENCHMARK(Skip10_ForwarQ128_1M) {
102 bmSkip<bm::Reader>(bm::list, bm::data, 10, bm::k1M);
105 BENCHMARK(Skip100_ForwardQ128_1M) {
106 bmSkip<bm::Reader>(bm::list, bm::data, 100, bm::k1M);
109 BENCHMARK(Skip1000_ForwardQ128_1M) {
110 bmSkip<bm::Reader>(bm::list, bm::data, 1000, bm::k1M);
113 BENCHMARK(SkipTo1_SkipQ128_1M) {
114 bmSkipTo<bm::Reader>(bm::list, bm::data, 1, bm::k1M);
117 BENCHMARK(SkipTo10_SkipQ128_1M) {
118 bmSkipTo<bm::Reader>(bm::list, bm::data, 10, bm::k1M);
121 BENCHMARK(SkipTo100_SkipQ128_1M) {
122 bmSkipTo<bm::Reader>(bm::list, bm::data, 100, bm::k1M);
125 BENCHMARK(SkipTo1000_SkipQ128_1M) {
126 bmSkipTo<bm::Reader>(bm::list, bm::data, 1000, bm::k1M);
129 int main(int argc, char** argv) {
130 testing::InitGoogleTest(&argc, argv);
131 google::ParseCommandLineFlags(&argc, &argv, true);
133 auto ret = RUN_ALL_TESTS();
134 if (ret == 0 && FLAGS_benchmark) {
136 folly::runBenchmarks();