// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Mobius Forensic Toolkit
// Copyright (C) 2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020 Eduardo Aguiar
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
// Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include <mobius/bytearray.h>
#include <mobius/imagefile/imagefile.h>
#include <mobius/imagefile/imagefile_ewf.h>
#include <mobius/benchmark.h>

static void
benchmark_imagefile_ewf ()
{
  mobius::imagefile::imagefile_ewf out (mobius::imagefile::new_imagefile_by_url ("file:///tmp/benchmark.ewf", "ewf"));
  out.set_segment_size (100000000000);
  auto writer = out.new_writer ();

  mobius::benchmark benchmark ("mobius::imagefile::ewf (write)");
  mobius::bytearray data (512);
  std::uint64_t count = 0;

  while (count % 10000 || benchmark.mtime () < 1000)
    {
      data[count % 512]++;
      writer.write (data);
      count++;
    }

  benchmark.end (count * 512);
}

static void
benchmark_imagefile_ewf_fast ()
{
  mobius::imagefile::imagefile_ewf out (mobius::imagefile::new_imagefile_by_url ("file:///tmp/benchmark.ewf", "ewf"));
  out.set_segment_size (100000000000);
  out.set_compression_level (1);
  auto writer = out.new_writer ();

  mobius::benchmark benchmark ("mobius::imagefile::ewf (write - compression=fast)");
  mobius::bytearray data (512);
  std::uint64_t count = 0;

  while (count % 10000 || benchmark.mtime () < 1000)
    {
      data[count % 512]++;
      writer.write (data);
      count++;
    }

  benchmark.end (count * 512);
}

static void
benchmark_imagefile_ewf_best ()
{
  mobius::imagefile::imagefile_ewf out (mobius::imagefile::new_imagefile_by_url ("file:///tmp/benchmark.ewf", "ewf"));
  out.set_segment_size (100000000000);
  out.set_compression_level (2);
  auto writer = out.new_writer ();

  mobius::benchmark benchmark ("mobius::imagefile::ewf (write - compression=best)");
  mobius::bytearray data (512);
  std::uint64_t count = 0;

  while (count % 10000 || benchmark.mtime () < 1000)
    {
      data[count % 512]++;
      writer.write (data);
      count++;
    }

  benchmark.end (count * 512);
}

void
benchmark_imagefile ()
{
  benchmark_imagefile_ewf ();
  benchmark_imagefile_ewf_fast ();
  benchmark_imagefile_ewf_best ();
}
