#include "tile/base/encoding.h"

#include "benchmark/benchmark.h"
#include "tile/base/object_pool.h"
#include "tile/base/random.h"
#include "tile/testing/internal/random_string.h"

namespace tile {

void
Benchmark_Base64Encode(benchmark::State &state)
{
    std::string random_str;
    std::string out;
    while (state.KeepRunning()) {
        state.PauseTiming();
        testing::RandomString(&random_str);
        state.ResumeTiming();

        EncodeBase64(random_str, &out);
    }
}

void
Benchmark_Base64Decode(benchmark::State &state)
{
    std::string random_str;
    std::string base64;
    std::string plain_text;
    while (state.KeepRunning()) {
        state.PauseTiming();
        testing::RandomString(&random_str);
        EncodeBase64(random_str, &base64);
        state.ResumeTiming();

        DecodeBase64(base64, &plain_text);
    }
}

void
Benchmark_PercentEncode(benchmark::State &state)
{
    std::string random_str;
    std::string out;
    while (state.KeepRunning()) {
        state.PauseTiming();
        testing::RandomString(&random_str);
        state.ResumeTiming();
        EncodeBase64(random_str, &out);
    }
}

void
Benchmark_PercentDecode(benchmark::State &state)
{
    std::string random_str;
    std::string percent;
    std::string plain_text;
    while (state.KeepRunning()) {
        state.PauseTiming();
        testing::RandomString(&random_str);
        EncodePercent(random_str, &percent);
        state.ResumeTiming();
        DecodePercent(percent, &plain_text);
    }
}

void
Benchmark_HexEncode(benchmark::State &state)
{
    std::string random_str;
    std::string percent;
    while (state.KeepRunning()) {
        state.PauseTiming();
        testing::RandomString(&random_str);
        state.ResumeTiming();
        EncodeHex(random_str, &percent);
    }
}

void
Benchmark_HexDecode(benchmark::State &state)
{
    std::string random_str;
    std::string percent;
    std::string plain_text;
    while (state.KeepRunning()) {
        state.PauseTiming();
        testing::RandomString(&random_str);
        EncodeHex(random_str, &percent);
        state.ResumeTiming();
        DecodeHex(percent, &plain_text);
    }
}

BENCHMARK(Benchmark_Base64Encode);
BENCHMARK(Benchmark_Base64Decode);
BENCHMARK(Benchmark_PercentEncode);
BENCHMARK(Benchmark_PercentDecode);
BENCHMARK(Benchmark_HexEncode);
BENCHMARK(Benchmark_HexDecode);
}// namespace tile
