2017-04-14 08:18:32 +08:00
|
|
|
// Copyright (c) 2017 Thomas Fussell
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
// THE SOFTWARE
|
|
|
|
//
|
|
|
|
// @license: http://www.opensource.org/licenses/mit-license.php
|
|
|
|
// @author: see AUTHORS file
|
|
|
|
|
2016-02-06 23:04:41 +08:00
|
|
|
#include <chrono>
|
2016-12-03 23:31:30 +08:00
|
|
|
#include <iostream>
|
2017-04-14 08:18:32 +08:00
|
|
|
|
|
|
|
#include <helpers/timing.hpp>
|
2016-02-06 23:04:41 +08:00
|
|
|
#include <xlnt/xlnt.hpp>
|
|
|
|
|
2017-04-14 08:18:32 +08:00
|
|
|
namespace {
|
2016-02-06 23:04:41 +08:00
|
|
|
|
|
|
|
// Create a worksheet with variable width rows. Because data must be
|
|
|
|
// serialised row by row it is often the width of the rows which is most
|
|
|
|
// important.
|
2016-12-04 19:20:12 +08:00
|
|
|
void writer(int cols, int rows)
|
2016-02-06 23:04:41 +08:00
|
|
|
{
|
|
|
|
xlnt::workbook wb;
|
|
|
|
auto ws = wb.create_sheet();
|
|
|
|
|
|
|
|
for(int index = 0; index < rows; index++)
|
|
|
|
{
|
2016-12-04 19:20:12 +08:00
|
|
|
if ((index + 1) % (rows / 10) == 0)
|
|
|
|
{
|
|
|
|
std::string progress = std::string((index + 1) / (1 + rows / 10), '.');
|
|
|
|
std::cout << "\r" << progress;
|
|
|
|
std::cout.flush();
|
|
|
|
}
|
2016-02-06 23:04:41 +08:00
|
|
|
|
2017-03-22 07:14:27 +08:00
|
|
|
for (int i = 0; i < cols; i++)
|
|
|
|
{
|
|
|
|
ws.cell(xlnt::cell_reference(i + 1, index + 1)).value(i);
|
|
|
|
}
|
2016-02-06 23:04:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << std::endl;
|
|
|
|
|
2017-04-14 08:18:32 +08:00
|
|
|
auto filename = "benchmark.xlsx";
|
2016-02-06 23:04:41 +08:00
|
|
|
wb.save(filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a timeit call to a function and pass in keyword arguments.
|
|
|
|
// The function is called twice, once using the standard workbook, then with the optimised one.
|
|
|
|
// Time from the best of three is taken.
|
2017-04-14 07:01:30 +08:00
|
|
|
void timer(std::function<void(int, int)> fn, int cols, int rows)
|
2016-02-06 23:04:41 +08:00
|
|
|
{
|
2017-04-14 08:18:32 +08:00
|
|
|
using xlnt::benchmarks::current_time;
|
|
|
|
|
2016-12-04 19:20:12 +08:00
|
|
|
const auto repeat = std::size_t(3);
|
|
|
|
auto time = std::numeric_limits<std::size_t>::max();
|
2016-02-06 23:04:41 +08:00
|
|
|
|
2016-12-04 19:20:12 +08:00
|
|
|
std::cout << cols << " cols " << rows << " rows" << std::endl;
|
2016-02-06 23:04:41 +08:00
|
|
|
|
2016-12-04 19:20:12 +08:00
|
|
|
for(int i = 0; i < repeat; i++)
|
|
|
|
{
|
|
|
|
auto start = current_time();
|
|
|
|
fn(cols, rows);
|
|
|
|
time = std::min(current_time() - start, time);
|
2016-02-06 23:04:41 +08:00
|
|
|
}
|
|
|
|
|
2016-12-04 19:20:12 +08:00
|
|
|
std::cout << time / 1000.0 << std::endl;
|
2016-02-06 23:04:41 +08:00
|
|
|
}
|
|
|
|
|
2017-04-14 08:18:32 +08:00
|
|
|
} // namespace
|
|
|
|
|
2016-02-06 23:04:41 +08:00
|
|
|
int main()
|
|
|
|
{
|
|
|
|
timer(&writer, 100, 100);
|
|
|
|
timer(&writer, 1000, 100);
|
|
|
|
timer(&writer, 4000, 100);
|
|
|
|
timer(&writer, 8192, 100);
|
|
|
|
timer(&writer, 10, 10000);
|
|
|
|
timer(&writer, 4000, 1000);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|