2 * Copyright 2013 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/experimental/test/CodingTestUtils.h"
18 #include "folly/experimental/EliasFanoCoding.h"
19 #include "folly/Benchmark.h"
21 using namespace folly::compression;
25 typedef EliasFanoReader<List> Reader;
26 testAll<Reader, List>(generateRandomList(100 * 1000, 10 * 1000 * 1000));
27 testAll<Reader, List>(generateSeqList(1, 100000, 100));
30 TEST(EliasFanoCompressedList, Empty) {
31 typedef EliasFanoCompressedList<uint32_t> List;
32 typedef EliasFanoReader<List> Reader;
33 testEmpty<Reader, List>();
36 TEST(EliasFanoCompressedList, Simple) {
37 testAll<EliasFanoCompressedList<uint32_t> >();
40 TEST(EliasFanoCompressedList, SkipPointers) {
41 testAll<EliasFanoCompressedList<uint32_t, uint32_t, 128, 0> >();
44 TEST(EliasFanoCompressedList, ForwardPointers) {
45 testAll<EliasFanoCompressedList<uint32_t, uint32_t, 0, 128> >();
48 TEST(EliasFanoCompressedList, SkipForwardPointers) {
49 testAll<EliasFanoCompressedList<uint32_t, uint32_t, 128, 128> >();
54 constexpr size_t k1M = 1000000;
55 typedef EliasFanoCompressedList<uint32_t, uint32_t, 128, 128> List;
56 typedef EliasFanoReader<List> Reader;
58 std::vector<uint32_t> data;
62 data = generateRandomList(100 * 1000, 10 * 1000 * 1000);
63 //data = loadList("/home/philipp/pl_test_dump.txt");
64 List::encode(data.data(), data.size(), bm::list);
74 bmNext<bm::Reader>(bm::list, bm::data, bm::k1M);
77 BENCHMARK(Skip1_ForwarQ128_1M) {
78 bmSkip<bm::Reader>(bm::list, bm::data, 1, bm::k1M);
81 BENCHMARK(Skip10_ForwarQ128_1M) {
82 bmSkip<bm::Reader>(bm::list, bm::data, 10, bm::k1M);
85 BENCHMARK(Skip100_ForwardQ128_1M) {
86 bmSkip<bm::Reader>(bm::list, bm::data, 100, bm::k1M);
89 BENCHMARK(Skip1000_ForwardQ128_1M) {
90 bmSkip<bm::Reader>(bm::list, bm::data, 1000, bm::k1M);
93 BENCHMARK(SkipTo1_SkipQ128_1M) {
94 bmSkipTo<bm::Reader>(bm::list, bm::data, 1, bm::k1M);
97 BENCHMARK(SkipTo10_SkipQ128_1M) {
98 bmSkipTo<bm::Reader>(bm::list, bm::data, 10, bm::k1M);
101 BENCHMARK(SkipTo100_SkipQ128_1M) {
102 bmSkipTo<bm::Reader>(bm::list, bm::data, 100, bm::k1M);
105 BENCHMARK(SkipTo1000_SkipQ128_1M) {
106 bmSkipTo<bm::Reader>(bm::list, bm::data, 1000, bm::k1M);
109 int main(int argc, char** argv) {
110 testing::InitGoogleTest(&argc, argv);
111 google::ParseCommandLineFlags(&argc, &argv, true);
113 auto ret = RUN_ALL_TESTS();
114 if (ret == 0 && FLAGS_benchmark) {
116 folly::runBenchmarks();