mirror of
https://github.com/boostorg/container.git
synced 2025-08-02 14:04:26 +02:00
Improved set test with search functions and added set<string> test to benchmark.
This commit is contained in:
@@ -11,160 +11,230 @@
|
||||
#include "boost/container/set.hpp"
|
||||
#include "boost/container/flat_set.hpp"
|
||||
#include "boost/container/allocator.hpp"
|
||||
#include <boost/container/vector.hpp>
|
||||
#include <boost/container/string.hpp>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <boost/timer/timer.hpp>
|
||||
#include <algorithm>
|
||||
#include <exception>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
using boost::timer::cpu_timer;
|
||||
using boost::timer::cpu_times;
|
||||
using boost::timer::nanosecond_type;
|
||||
using namespace boost::container;
|
||||
|
||||
#ifdef NDEBUG
|
||||
static const std::size_t N = 500;
|
||||
static const std::size_t N = 1000;
|
||||
#else
|
||||
static const std::size_t N = 50;
|
||||
static const std::size_t N = 100;
|
||||
#endif
|
||||
|
||||
void compare_times(cpu_times time_numerator, cpu_times time_denominator){
|
||||
std::cout << "----------------------------------------------" << '\n';
|
||||
std::cout << " wall = " << ((double)time_numerator.wall/(double)time_denominator.wall) << std::endl;
|
||||
std::cout << ((double)time_numerator.wall/(double)time_denominator.wall) << std::endl;
|
||||
std::cout << "----------------------------------------------" << '\n' << std::endl;
|
||||
}
|
||||
|
||||
std::vector<int> sorted_unique_range;
|
||||
std::vector<int> sorted_range;
|
||||
std::vector<int> random_unique_range;
|
||||
std::vector<int> random_range;
|
||||
vector<int> sorted_unique_range_int;
|
||||
vector<int> sorted_range_int;
|
||||
vector<int> random_unique_range_int;
|
||||
vector<int> random_range_int;
|
||||
|
||||
void fill_ranges()
|
||||
void fill_range_ints()
|
||||
{
|
||||
sorted_unique_range.resize(N);
|
||||
sorted_range.resize(N);
|
||||
random_unique_range.resize(N);
|
||||
random_range.resize(N);
|
||||
std::srand (0);
|
||||
//random_range
|
||||
std::generate(random_unique_range.begin(), random_unique_range.end(), std::rand);
|
||||
random_unique_range.erase(std::unique(random_unique_range.begin(), random_unique_range.end()), random_unique_range.end());
|
||||
//random_range
|
||||
random_range = random_unique_range;
|
||||
random_range.insert(random_range.end(), random_unique_range.begin(), random_unique_range.end());
|
||||
//sorted_unique_range
|
||||
for(std::size_t i = 0, max = sorted_unique_range.size(); i != max; ++i){
|
||||
sorted_unique_range[i] = static_cast<int>(i);
|
||||
//sorted_unique_range_int
|
||||
sorted_unique_range_int.resize(N);
|
||||
for(std::size_t i = 0, max = sorted_unique_range_int.size(); i != max; ++i){
|
||||
sorted_unique_range_int[i] = static_cast<int>(i);
|
||||
}
|
||||
//sorted_range
|
||||
sorted_range = sorted_unique_range;
|
||||
sorted_range.insert(sorted_range.end(), sorted_unique_range.begin(), sorted_unique_range.end());
|
||||
std::sort(sorted_range.begin(), sorted_range.end());
|
||||
//sorted_range_int
|
||||
sorted_range_int = sorted_unique_range_int;
|
||||
sorted_range_int.insert(sorted_range_int.end(), sorted_unique_range_int.begin(), sorted_unique_range_int.end());
|
||||
std::sort(sorted_range_int.begin(), sorted_range_int.end());
|
||||
|
||||
//random_range_int
|
||||
std::srand(0);
|
||||
random_range_int.assign(sorted_range_int.begin(), sorted_range_int.end());
|
||||
std::random_shuffle(random_range_int.begin(), random_range_int.end());
|
||||
//random_unique_range_int
|
||||
std::srand(0);
|
||||
random_unique_range_int.assign(sorted_unique_range_int.begin(), sorted_unique_range_int.end());
|
||||
std::random_shuffle(random_unique_range_int.begin(), random_unique_range_int.end());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
cpu_times construct_time()
|
||||
vector<string> sorted_unique_range_string;
|
||||
vector<string> sorted_range_string;
|
||||
vector<string> random_unique_range_string;
|
||||
vector<string> random_range_string;
|
||||
|
||||
void fill_range_strings()
|
||||
{
|
||||
cpu_timer sur_timer, sr_timer, rur_timer, rr_timer, copy_timer, assign_timer, destroy_timer;
|
||||
//sur_timer.stop();sr_timer.stop();rur_timer.stop();rr_timer.stop();destroy_timer.stop();
|
||||
//sorted_unique_range_int
|
||||
sorted_unique_range_string.resize(N);
|
||||
for(std::size_t i = 0, max = sorted_unique_range_string.size(); i != max; ++i){
|
||||
std::stringstream sstr;
|
||||
sstr << std::setfill('0') << std::setw(10) << i;
|
||||
sorted_unique_range_string[i] = "really_long_long_prefix_to_ssb_and_increase_comparison_costs_";
|
||||
const std::string &s = sstr.str();
|
||||
sorted_unique_range_string[i].append(s.begin(), s.end());
|
||||
}
|
||||
//sorted_range_string
|
||||
sorted_range_string = sorted_unique_range_string;
|
||||
sorted_range_string.insert(sorted_range_string.end(), sorted_unique_range_string.begin(), sorted_unique_range_string.end());
|
||||
std::sort(sorted_range_string.begin(), sorted_range_string.end());
|
||||
|
||||
//random_range_string
|
||||
std::srand(0);
|
||||
random_range_string.assign(sorted_range_string.begin(), sorted_range_string.end());
|
||||
std::random_shuffle(random_range_string.begin(), random_range_string.end());
|
||||
//random_unique_range_string
|
||||
std::srand(0);
|
||||
random_unique_range_string.assign(sorted_unique_range_string.begin(), sorted_unique_range_string.end());
|
||||
std::random_shuffle(random_unique_range_string.begin(), random_unique_range_string.end());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
struct range_provider;
|
||||
|
||||
template<>
|
||||
struct range_provider<int>
|
||||
{
|
||||
typedef vector<int> type;
|
||||
|
||||
static type &sorted_unique()
|
||||
{ return sorted_unique_range_int; }
|
||||
|
||||
static type &sorted()
|
||||
{ return sorted_range_int; }
|
||||
|
||||
static type &random_unique()
|
||||
{ return random_unique_range_int; }
|
||||
|
||||
static type &random()
|
||||
{ return random_range_int; }
|
||||
};
|
||||
|
||||
template<>
|
||||
struct range_provider<string>
|
||||
{
|
||||
typedef vector<string> type;
|
||||
|
||||
static type &sorted_unique()
|
||||
{ return sorted_unique_range_string; }
|
||||
|
||||
static type &sorted()
|
||||
{ return sorted_range_string; }
|
||||
|
||||
static type &random_unique()
|
||||
{ return random_unique_range_string; }
|
||||
|
||||
static type &random()
|
||||
{ return random_range_string; }
|
||||
};
|
||||
|
||||
template<typename C>
|
||||
cpu_times copy_destroy_time(vector<typename C::value_type> &unique_range)
|
||||
{
|
||||
cpu_timer copy_timer, assign_timer, destroy_timer;
|
||||
|
||||
cpu_timer total_time;
|
||||
total_time.resume();
|
||||
|
||||
for(std::size_t i = 0; i != N; ++i){
|
||||
{
|
||||
sur_timer.resume();
|
||||
T t(sorted_unique_range.begin(), sorted_unique_range.end());
|
||||
sur_timer.stop();
|
||||
}
|
||||
{
|
||||
sr_timer.resume();
|
||||
T t(sorted_range.begin(), sorted_range.end());
|
||||
sr_timer.stop();
|
||||
C c(unique_range.begin(), unique_range.end());
|
||||
total_time.resume();
|
||||
copy_timer.resume();
|
||||
T taux(t);
|
||||
C caux(c);
|
||||
copy_timer.stop();
|
||||
assign_timer.resume();
|
||||
t = taux;;
|
||||
c = caux;
|
||||
assign_timer.stop();
|
||||
}
|
||||
{
|
||||
rur_timer.resume();
|
||||
T t(random_unique_range.begin(), random_unique_range.end());
|
||||
rur_timer.stop();
|
||||
}
|
||||
{
|
||||
rr_timer.resume();
|
||||
T t(random_range.begin(), random_range.end());
|
||||
rr_timer.stop();
|
||||
destroy_timer.resume();
|
||||
}
|
||||
destroy_timer.stop();
|
||||
total_time.stop();
|
||||
}
|
||||
total_time.stop();
|
||||
|
||||
std::cout << " Construct sorted_unique_range " << boost::timer::format(sur_timer.elapsed(), boost::timer::default_places, "%ws wall\n");
|
||||
std::cout << " Construct sorted_range " << boost::timer::format(sr_timer.elapsed(), boost::timer::default_places, "%ws wall\n");
|
||||
std::cout << " Copy sorted range " << boost::timer::format(copy_timer.elapsed(), boost::timer::default_places, "%ws wall\n");
|
||||
std::cout << " Assign sorted range " << boost::timer::format(assign_timer.elapsed(), boost::timer::default_places, "%ws wall\n");
|
||||
std::cout << " Construct random_unique_range " << boost::timer::format(rur_timer.elapsed(), boost::timer::default_places, "%ws wall\n");
|
||||
std::cout << " Construct random_range " << boost::timer::format(rr_timer.elapsed(), boost::timer::default_places, "%ws wall\n");
|
||||
std::cout << " Destroy " << boost::timer::format(destroy_timer.elapsed(), boost::timer::default_places, "%ws wall\n");
|
||||
std::cout << " Total time = " << boost::timer::format(total_time.elapsed(), boost::timer::default_places, "%ws wall\n") << std::endl;
|
||||
std::cout << " Copy sorted range " << boost::timer::format(copy_timer.elapsed(), boost::timer::default_places, "%ws\n");
|
||||
std::cout << " Assign sorted range " << boost::timer::format(assign_timer.elapsed(), boost::timer::default_places, "%ws\n");
|
||||
std::cout << " Destroy " << boost::timer::format(destroy_timer.elapsed(), boost::timer::default_places, "%ws\n");
|
||||
std::cout << " Total time = " << boost::timer::format(total_time.elapsed(), boost::timer::default_places, "%ws\n") << std::endl;
|
||||
return total_time.elapsed();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
cpu_times insert_time()
|
||||
template<typename C>
|
||||
cpu_times construct_time(vector<typename C::value_type> &unique_range, vector<typename C::value_type> &range, const char *RangeType)
|
||||
{
|
||||
cpu_timer sur_timer,sr_timer,rur_timer,rr_timer,destroy_timer;
|
||||
sur_timer.stop();sr_timer.stop();rur_timer.stop();rr_timer.stop();
|
||||
cpu_timer sur_timer, sr_timer;
|
||||
|
||||
cpu_timer total_time;
|
||||
|
||||
for(std::size_t i = 0; i != N; ++i){
|
||||
{
|
||||
sur_timer.resume();
|
||||
total_time.resume();
|
||||
C c(unique_range.begin(), unique_range.end());
|
||||
sur_timer.stop();
|
||||
total_time.stop();
|
||||
}
|
||||
{
|
||||
total_time.resume();
|
||||
sr_timer.resume();
|
||||
C c(range.begin(), range.end());
|
||||
sr_timer.stop();
|
||||
total_time.stop();
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << " Construct " << RangeType << " unique_range " << boost::timer::format(sur_timer.elapsed(), boost::timer::default_places, "%ws\n");
|
||||
std::cout << " Construct " << RangeType << " range " << boost::timer::format(sr_timer.elapsed(), boost::timer::default_places, "%ws\n");
|
||||
std::cout << " Total time = " << boost::timer::format(total_time.elapsed(), boost::timer::default_places, "%ws\n") << std::endl;
|
||||
return total_time.elapsed();
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
cpu_times insert_time(vector<typename C::value_type> &unique_range, vector<typename C::value_type> &range, const char *RangeType)
|
||||
{
|
||||
cpu_timer ur_timer,r_timer;
|
||||
ur_timer.stop();r_timer.stop();
|
||||
|
||||
cpu_timer total_time;
|
||||
total_time.resume();
|
||||
|
||||
for(std::size_t i = 0; i != N; ++i){
|
||||
{
|
||||
sur_timer.resume();
|
||||
T t;
|
||||
t.insert(sorted_unique_range.begin(), sorted_unique_range.end());
|
||||
sur_timer.stop();
|
||||
}
|
||||
{
|
||||
sr_timer.resume();
|
||||
T t;
|
||||
t.insert(sorted_range.begin(), sorted_range.end());
|
||||
sr_timer.stop();
|
||||
}
|
||||
{
|
||||
rur_timer.resume();
|
||||
T t;
|
||||
t.insert(random_unique_range.begin(), random_unique_range.end());
|
||||
rur_timer.stop();
|
||||
}
|
||||
{
|
||||
rr_timer.resume();
|
||||
T t;
|
||||
t.insert(random_range.begin(), random_range.end());
|
||||
rr_timer.stop();
|
||||
}
|
||||
}
|
||||
total_time.resume();
|
||||
ur_timer.resume();
|
||||
C c;
|
||||
c.insert(unique_range.begin(), unique_range.end());
|
||||
ur_timer.stop();
|
||||
total_time.stop();
|
||||
}
|
||||
{
|
||||
total_time.resume();
|
||||
r_timer.resume();
|
||||
C c;
|
||||
c.insert(range.begin(), range.end());
|
||||
r_timer.stop();
|
||||
total_time.stop();
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << " Insert sorted_unique_range " << boost::timer::format(sur_timer.elapsed(), boost::timer::default_places, "%ws wall\n");
|
||||
std::cout << " Insert sorted_range " << boost::timer::format(sr_timer.elapsed(), boost::timer::default_places, "%ws wall\n");
|
||||
std::cout << " Insert random_unique_range " << boost::timer::format(rur_timer.elapsed(), boost::timer::default_places, "%ws wall\n");
|
||||
std::cout << " Insert random_range " << boost::timer::format(rr_timer.elapsed(), boost::timer::default_places, "%ws wall\n");
|
||||
std::cout << " Total time = " << boost::timer::format(total_time.elapsed(), boost::timer::default_places, "%ws wall\n") << std::endl;
|
||||
std::cout << " Insert " << RangeType << " unique_range " << boost::timer::format(ur_timer.elapsed(), boost::timer::default_places, "%ws\n");
|
||||
std::cout << " Insert " << RangeType << " range " << boost::timer::format(r_timer.elapsed(), boost::timer::default_places, "%ws\n");
|
||||
std::cout << " Total time = " << boost::timer::format(total_time.elapsed(), boost::timer::default_places, "%ws\n") << std::endl;
|
||||
return total_time.elapsed();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
cpu_times search_time()
|
||||
template<typename C>
|
||||
cpu_times search_time(vector<typename C::value_type> &unique_range, const char *RangeType)
|
||||
{
|
||||
cpu_timer find_timer, lower_timer, upper_timer, equal_range_timer, count_timer;
|
||||
|
||||
T t(sorted_unique_range.begin(), sorted_unique_range.end());
|
||||
C c(unique_range.begin(), unique_range.end());
|
||||
|
||||
cpu_timer total_time;
|
||||
total_time.resume();
|
||||
@@ -174,95 +244,84 @@ cpu_times search_time()
|
||||
{
|
||||
std::size_t found = 0;
|
||||
find_timer.resume();
|
||||
for(std::size_t i = 0, max = sorted_unique_range.size(); i != max; ++i){
|
||||
found += static_cast<std::size_t>(t.end() != t.find(sorted_unique_range[i]));
|
||||
}
|
||||
for(std::size_t i = 0, max = sorted_unique_range.size(); i != max; ++i){
|
||||
found += static_cast<std::size_t>(t.end() != t.find(sorted_unique_range[i]));
|
||||
for(std::size_t rep = 0; rep != 2; ++rep)
|
||||
for(std::size_t i = 0, max = unique_range.size(); i != max; ++i){
|
||||
found += static_cast<std::size_t>(c.end() != c.find(unique_range[i]));
|
||||
}
|
||||
find_timer.stop();
|
||||
if(found/2 != t.size()){
|
||||
std::cout << "ERROR! all elements not found" << std::endl;
|
||||
if(found/2 != c.size()){
|
||||
std::cout << "ERROR! find all elements not found" << std::endl;
|
||||
}
|
||||
}
|
||||
//Lower
|
||||
{
|
||||
std::size_t found = 0;
|
||||
lower_timer.resume();
|
||||
for(std::size_t i = 0, max = sorted_unique_range.size(); i != max; ++i){
|
||||
found += static_cast<std::size_t>(t.end() != t.lower_bound(sorted_unique_range[i]));
|
||||
}
|
||||
for(std::size_t i = 0, max = sorted_unique_range.size(); i != max; ++i){
|
||||
found += static_cast<std::size_t>(t.end() != t.lower_bound(sorted_unique_range[i]));
|
||||
for(std::size_t rep = 0; rep != 2; ++rep)
|
||||
for(std::size_t i = 0, max = unique_range.size(); i != max; ++i){
|
||||
found += static_cast<std::size_t>(c.end() != c.lower_bound(unique_range[i]));
|
||||
}
|
||||
lower_timer.stop();
|
||||
if(found/2 != t.size()){
|
||||
std::cout << "ERROR! all elements not found" << std::endl;
|
||||
if(found/2 != c.size()){
|
||||
std::cout << "ERROR! lower_bound all elements not found" << std::endl;
|
||||
}
|
||||
}
|
||||
//Upper
|
||||
{
|
||||
std::size_t found = 0;
|
||||
upper_timer.resume();
|
||||
for(std::size_t i = 0, max = sorted_unique_range.size(); i != max; ++i){
|
||||
found += static_cast<std::size_t>(t.end() != t.upper_bound(sorted_unique_range[i]));
|
||||
}
|
||||
for(std::size_t i = 0, max = sorted_unique_range.size(); i != max; ++i){
|
||||
found += static_cast<std::size_t>(t.end() != t.upper_bound(sorted_unique_range[i]));
|
||||
for(std::size_t rep = 0; rep != 2; ++rep)
|
||||
for(std::size_t i = 0, max = unique_range.size(); i != max; ++i){
|
||||
found += static_cast<std::size_t>(c.end() != c.upper_bound(unique_range[i]));
|
||||
}
|
||||
upper_timer.stop();
|
||||
if(found/2 != (t.size()-1)){
|
||||
std::cout << "ERROR! all elements not found" << std::endl;
|
||||
if(found/2 != (c.size()-1)){
|
||||
std::cout << "ERROR! upper_bound all elements not found" << std::endl;
|
||||
}
|
||||
}
|
||||
//Equal
|
||||
{
|
||||
std::size_t found = 0;
|
||||
std::pair<typename T::iterator,typename T::iterator> ret;
|
||||
std::pair<typename C::iterator,typename C::iterator> ret;
|
||||
equal_range_timer.resume();
|
||||
for(std::size_t i = 0, max = sorted_unique_range.size(); i != max; ++i){
|
||||
ret = t.equal_range(sorted_unique_range[i]);
|
||||
found += static_cast<std::size_t>(ret.first != ret.second);
|
||||
}
|
||||
for(std::size_t i = 0, max = sorted_unique_range.size(); i != max; ++i){
|
||||
ret = t.equal_range(sorted_unique_range[i]);
|
||||
for(std::size_t rep = 0; rep != 2; ++rep)
|
||||
for(std::size_t i = 0, max = unique_range.size(); i != max; ++i){
|
||||
ret = c.equal_range(unique_range[i]);
|
||||
found += static_cast<std::size_t>(ret.first != ret.second);
|
||||
}
|
||||
equal_range_timer.stop();
|
||||
if(found/2 != t.size()){
|
||||
std::cout << "ERROR! all elements not found" << std::endl;
|
||||
if(found/2 != c.size()){
|
||||
std::cout << "ERROR! equal_range all elements not found" << std::endl;
|
||||
}
|
||||
}
|
||||
//Count
|
||||
{
|
||||
std::size_t found = 0;
|
||||
std::pair<typename T::iterator,typename T::iterator> ret;
|
||||
std::pair<typename C::iterator,typename C::iterator> ret;
|
||||
count_timer.resume();
|
||||
for(std::size_t i = 0, max = sorted_unique_range.size(); i != max; ++i){
|
||||
found += static_cast<std::size_t>(t.count(sorted_unique_range[i]));
|
||||
}
|
||||
for(std::size_t i = 0, max = sorted_unique_range.size(); i != max; ++i){
|
||||
found += static_cast<std::size_t>(t.count(sorted_unique_range[i]));
|
||||
for(std::size_t rep = 0; rep != 2; ++rep)
|
||||
for(std::size_t i = 0, max = unique_range.size(); i != max; ++i){
|
||||
found += static_cast<std::size_t>(c.count(unique_range[i]));
|
||||
}
|
||||
count_timer.stop();
|
||||
if(found/2 != t.size()){
|
||||
std::cout << "ERROR! all elements not found" << std::endl;
|
||||
if(found/2 != c.size()){
|
||||
std::cout << "ERROR! count all elements not found" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
total_time.stop();
|
||||
|
||||
std::cout << " Find " << boost::timer::format(find_timer.elapsed(), boost::timer::default_places, "%ws wall\n");
|
||||
std::cout << " Lower Bound " << boost::timer::format(lower_timer.elapsed(), boost::timer::default_places, "%ws wall\n");
|
||||
std::cout << " Upper Bound " << boost::timer::format(upper_timer.elapsed(), boost::timer::default_places, "%ws wall\n");
|
||||
std::cout << " Equal Range " << boost::timer::format(equal_range_timer.elapsed(), boost::timer::default_places, "%ws wall\n");
|
||||
std::cout << " Count " << boost::timer::format(count_timer.elapsed(), boost::timer::default_places, "%ws wall\n");
|
||||
std::cout << " Total time = " << boost::timer::format(total_time.elapsed(), boost::timer::default_places, "%ws wall\n") << std::endl;
|
||||
std::cout << " Find " << RangeType << " " << boost::timer::format(find_timer.elapsed(), boost::timer::default_places, "%ws\n");
|
||||
std::cout << " Lower Bound " << RangeType << " " << boost::timer::format(lower_timer.elapsed(), boost::timer::default_places, "%ws\n");
|
||||
std::cout << " Upper Bound " << RangeType << " " << boost::timer::format(upper_timer.elapsed(), boost::timer::default_places, "%ws\n");
|
||||
std::cout << " Equal Range " << RangeType << " " << boost::timer::format(equal_range_timer.elapsed(), boost::timer::default_places, "%ws\n");
|
||||
std::cout << " Count " << RangeType << " " << boost::timer::format(count_timer.elapsed(), boost::timer::default_places, "%ws\n");
|
||||
std::cout << " Total time = " << boost::timer::format(total_time.elapsed(), boost::timer::default_places, "%ws\n") << std::endl;
|
||||
return total_time.elapsed();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void extensions_time()
|
||||
template<typename C>
|
||||
void extensions_time(vector<typename C::value_type> &sorted_unique_range)
|
||||
{
|
||||
cpu_timer sur_timer,sur_opt_timer;
|
||||
sur_timer.stop();sur_opt_timer.stop();
|
||||
@@ -270,69 +329,107 @@ void extensions_time()
|
||||
for(std::size_t i = 0; i != N; ++i){
|
||||
{
|
||||
sur_timer.resume();
|
||||
T t(sorted_unique_range.begin(), sorted_unique_range.end());
|
||||
C c(sorted_unique_range.begin(), sorted_unique_range.end());
|
||||
sur_timer.stop();
|
||||
}
|
||||
{
|
||||
sur_opt_timer.resume();
|
||||
T t(boost::container::ordered_unique_range, sorted_unique_range.begin(), sorted_unique_range.end());
|
||||
C c(boost::container::ordered_unique_range, sorted_unique_range.begin(), sorted_unique_range.end());
|
||||
sur_opt_timer.stop();
|
||||
}
|
||||
|
||||
}
|
||||
std::cout << " Construct sorted_unique_range " << boost::timer::format(sur_timer.elapsed(), boost::timer::default_places, "%ws wall\n");
|
||||
std::cout << " Construct sorted_unique_range (extension) " << boost::timer::format(sur_opt_timer.elapsed(), boost::timer::default_places, "%ws wall\n");
|
||||
std::cout << "Total time (Extension/Standard):\n";
|
||||
std::cout << " Construct sorted_unique_range " << boost::timer::format(sur_timer.elapsed(), boost::timer::default_places, "%ws\n");
|
||||
std::cout << " Construct sorted_unique_range (extension) " << boost::timer::format(sur_opt_timer.elapsed(), boost::timer::default_places, "%ws\n");
|
||||
std::cout << "Extension/Standard: ";
|
||||
compare_times(sur_opt_timer.elapsed(), sur_timer.elapsed());
|
||||
}
|
||||
|
||||
template<class BoostClass, class StdClass>
|
||||
void launch_tests(const char *BoostContName, const char *StdContName)
|
||||
{
|
||||
typedef range_provider<typename BoostClass::value_type> get_range_t;
|
||||
try {
|
||||
std::cout << "**********************************************" << '\n';
|
||||
std::cout << "**********************************************" << '\n';
|
||||
std::cout << "**********************************************" << '\n';
|
||||
std::cout << '\n';
|
||||
std::cout << BoostContName << " .VS " << StdContName << '\n';
|
||||
std::cout << '\n';
|
||||
std::cout << "**********************************************" << '\n';
|
||||
std::cout << "**********************************************" << '\n';
|
||||
std::cout << "**********************************************" << '\n' << std::endl;
|
||||
fill_ranges();
|
||||
{
|
||||
std::cout << "Construct benchmark:" << BoostContName << std::endl;
|
||||
cpu_times boost_set_time = construct_time< BoostClass >();
|
||||
std::cout << "Copy/Assign/Destroy benchmark:" << BoostContName << std::endl;
|
||||
cpu_times boost_set_time = copy_destroy_time< BoostClass >(get_range_t::sorted_unique());
|
||||
|
||||
std::cout << "Construct benchmark:" << StdContName << std::endl;
|
||||
cpu_times std_set_time = construct_time< StdClass >();
|
||||
std::cout << "Copy/Assign/Destroy benchmark:" << StdContName << std::endl;
|
||||
cpu_times std_set_time = copy_destroy_time< StdClass >(get_range_t::sorted_unique());
|
||||
|
||||
std::cout << "Total time (" << BoostContName << "/" << StdContName << "):\n";
|
||||
std::cout << BoostContName << "/" << StdContName << ": ";
|
||||
compare_times(boost_set_time, std_set_time);
|
||||
}
|
||||
{
|
||||
std::cout << "Insert benchmark:" << BoostContName << std::endl;
|
||||
cpu_times boost_set_time = insert_time< BoostClass >();
|
||||
std::cout << "Ordered construct benchmark:" << BoostContName << std::endl;
|
||||
cpu_times boost_set_time = construct_time< BoostClass >(get_range_t::sorted_unique(), get_range_t::sorted(), "(ord)");
|
||||
|
||||
std::cout << "Insert benchmark:" << StdContName << std::endl;
|
||||
cpu_times std_set_time = insert_time< StdClass >();
|
||||
std::cout << "Ordered construct benchmark:" << StdContName << std::endl;
|
||||
cpu_times std_set_time = construct_time< StdClass >(get_range_t::sorted_unique(), get_range_t::sorted(), "(ord)");;
|
||||
|
||||
std::cout << "Total time (" << BoostContName << "/" << StdContName << "):\n";
|
||||
std::cout << BoostContName << "/" << StdContName << ": ";
|
||||
compare_times(boost_set_time, std_set_time);
|
||||
}
|
||||
{
|
||||
std::cout << "Search benchmark:" << BoostContName << std::endl;
|
||||
cpu_times boost_set_time = search_time< BoostClass >();
|
||||
std::cout << "Random construct benchmark:" << BoostContName << std::endl;
|
||||
cpu_times boost_set_time = construct_time< BoostClass >(get_range_t::random_unique(), get_range_t::random(), "(rnd)");
|
||||
|
||||
std::cout << "Search benchmark:" << StdContName << std::endl;
|
||||
cpu_times std_set_time = search_time< StdClass >();
|
||||
std::cout << "Random construct benchmark:" << StdContName << std::endl;
|
||||
cpu_times std_set_time = construct_time< StdClass >(get_range_t::random_unique(), get_range_t::random(), "(rnd)");;
|
||||
|
||||
std::cout << "Total time (" << BoostContName << "/" << StdContName << "):\n";
|
||||
std::cout << BoostContName << "/" << StdContName << ": ";
|
||||
compare_times(boost_set_time, std_set_time);
|
||||
}
|
||||
{
|
||||
std::cout << "Ordered Insert benchmark:" << BoostContName << std::endl;
|
||||
cpu_times boost_set_time = insert_time< BoostClass >(get_range_t::sorted_unique(), get_range_t::sorted(), "(ord)");
|
||||
|
||||
std::cout << "Ordered Insert benchmark:" << StdContName << std::endl;
|
||||
cpu_times std_set_time = insert_time< StdClass >(get_range_t::sorted_unique(), get_range_t::sorted(), "(ord)");
|
||||
|
||||
std::cout << BoostContName << "/" << StdContName << ": ";
|
||||
compare_times(boost_set_time, std_set_time);
|
||||
}
|
||||
{
|
||||
std::cout << "Random Insert benchmark:" << BoostContName << std::endl;
|
||||
cpu_times boost_set_time = insert_time< BoostClass >(get_range_t::random_unique(), get_range_t::random(), "(rnd)");
|
||||
|
||||
std::cout << "Random Insert benchmark:" << StdContName << std::endl;
|
||||
cpu_times std_set_time = insert_time< StdClass >(get_range_t::random_unique(), get_range_t::random(), "(rnd)");
|
||||
|
||||
std::cout << BoostContName << "/" << StdContName << ": ";
|
||||
compare_times(boost_set_time, std_set_time);
|
||||
}
|
||||
{
|
||||
std::cout << "Ordered Search benchmark:" << BoostContName << std::endl;
|
||||
cpu_times boost_set_time = search_time< BoostClass >(get_range_t::sorted_unique(), "(ord)");
|
||||
|
||||
std::cout << "Ordered Search benchmark:" << StdContName << std::endl;
|
||||
cpu_times std_set_time = search_time< StdClass >(get_range_t::sorted_unique(), "(ord)");
|
||||
|
||||
std::cout << BoostContName << "/" << StdContName << ": ";
|
||||
compare_times(boost_set_time, std_set_time);
|
||||
}
|
||||
{
|
||||
std::cout << "Random Search benchmark:" << BoostContName << std::endl;
|
||||
cpu_times boost_set_time = search_time< BoostClass >(get_range_t::random_unique(), "(rnd)");
|
||||
|
||||
std::cout << "Random Search benchmark:" << StdContName << std::endl;
|
||||
cpu_times std_set_time = search_time< StdClass >(get_range_t::random_unique(), "(rnd)");
|
||||
|
||||
std::cout << BoostContName << "/" << StdContName << ": ";
|
||||
compare_times(boost_set_time, std_set_time);
|
||||
}
|
||||
{
|
||||
std::cout << "Extensions benchmark:" << BoostContName << std::endl;
|
||||
extensions_time< BoostClass >();
|
||||
extensions_time< BoostClass >(get_range_t::sorted_unique());
|
||||
}
|
||||
|
||||
}catch(std::exception e){
|
||||
@@ -343,6 +440,11 @@ void launch_tests(const char *BoostContName, const char *StdContName)
|
||||
int main()
|
||||
{
|
||||
using namespace boost::container;
|
||||
//////////////////////////////////
|
||||
// INT
|
||||
//////////////////////////////////
|
||||
|
||||
fill_range_ints();
|
||||
//set vs std::set
|
||||
launch_tests< set<int> , std::set<int> >
|
||||
("set<int>", "std::set<int>");
|
||||
@@ -352,6 +454,7 @@ int main()
|
||||
//set(RB) vs set(SG)
|
||||
launch_tests< set<int>, set<int, std::less<int>, std::allocator<int>, tree_assoc_options< tree_type<scapegoat_tree> >::type > >
|
||||
("set<int>(RB)", "set<int>(SG)");
|
||||
//set(RB) vs set(SP)
|
||||
launch_tests< set<int>, set<int, std::less<int>, std::allocator<int>, tree_assoc_options< tree_type<splay_tree> >::type > >
|
||||
("set<int>(RB)", "set<int>(SP)");
|
||||
//set(sizeopt) vs set(!sizeopt)
|
||||
@@ -373,5 +476,42 @@ int main()
|
||||
//flat_multiset vs multiset
|
||||
launch_tests< flat_multiset<int> , multiset<int> >
|
||||
("flat_multiset<int>", "multiset<int>");
|
||||
|
||||
//////////////////////////////////
|
||||
// STRING
|
||||
//////////////////////////////////
|
||||
fill_range_strings();
|
||||
|
||||
//set vs std::set
|
||||
launch_tests< set<string> , std::set<string> >
|
||||
("set<string>", "std::set<string>");
|
||||
//set(RB) vs set(AVL)
|
||||
launch_tests< set<string>, set<string, std::less<string>, std::allocator<string>, tree_assoc_options< tree_type<avl_tree> >::type > >
|
||||
("set<string>(RB)", "set<string>(AVL)");
|
||||
//set(RB) vs set(SG)
|
||||
launch_tests< set<string>, set<string, std::less<string>, std::allocator<string>, tree_assoc_options< tree_type<scapegoat_tree> >::type > >
|
||||
("set<string>(RB)", "set<string>(SG)");
|
||||
//set(RB) vs set(SP)
|
||||
launch_tests< set<string>, set<string, std::less<string>, std::allocator<string>, tree_assoc_options< tree_type<splay_tree> >::type > >
|
||||
("set<string>(RB)", "set<string>(SP)");
|
||||
//set(sizeopt) vs set(!sizeopt)
|
||||
launch_tests< set<string>, set<string, std::less<string>, std::allocator<string>, tree_assoc_options< optimize_size<false> >::type > >
|
||||
("set<string>(sizeopt=true)", "set<string>(sizeopt=false)");
|
||||
//set(AVL,sizeopt) vs set(AVL,!sizeopt)
|
||||
launch_tests< set<string, std::less<string>, std::allocator<string>, tree_assoc_options< tree_type<avl_tree> >::type >
|
||||
, set<string, std::less<string>, std::allocator<string>, tree_assoc_options< tree_type<avl_tree>, optimize_size<false> >::type > >
|
||||
("set<string>(AVL,sizeopt=true)", "set<string>(AVL,sizeopt=false)");
|
||||
//set vs set<..., allocator_v2>
|
||||
launch_tests< set<string> , set<string, std::less<string>, allocator<string> > >
|
||||
("set<string>", "set<string, ..., allocator<string>" );
|
||||
//multiset vs std::set
|
||||
launch_tests< multiset<string> , std::multiset<string> >
|
||||
("multiset<string>", "std::multiset<string>");
|
||||
//flat_set vs set
|
||||
launch_tests< flat_set<string> , set<string> >
|
||||
("flat_set<string>", "set<string>");
|
||||
//flat_multiset vs multiset
|
||||
launch_tests< flat_multiset<string> , multiset<string> >
|
||||
("flat_multiset<string>", "multiset<string>");
|
||||
return 0;
|
||||
}
|
||||
|
@@ -30,6 +30,23 @@ bool CheckEqual( const T1 &t1, const T2 &t2
|
||||
>::type* = 0)
|
||||
{ return t1 == t2; }
|
||||
|
||||
|
||||
template<class T1, class T2, class C1, class C2>
|
||||
bool CheckEqualIt( const T1 &i1, const T2 &i2, const C1 &c1, const C2 &c2 )
|
||||
{
|
||||
bool c1end = i1 == c1.end();
|
||||
bool c2end = i2 == c2.end();
|
||||
if( c1end != c2end ){
|
||||
return false;
|
||||
}
|
||||
else if(c1end){
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
return CheckEqual(*i1, *i2);
|
||||
}
|
||||
}
|
||||
|
||||
template< class Pair1, class Pair2>
|
||||
bool CheckEqual( const Pair1 &pair1, const Pair2 &pair2
|
||||
, typename boost::container::container_detail::enable_if_c
|
||||
|
@@ -503,6 +503,99 @@ int set_test ()
|
||||
}
|
||||
}
|
||||
|
||||
//Compare find/lower_bound/upper_bound in set
|
||||
{
|
||||
typename MyBoostSet::iterator bs_b = boostset->begin();
|
||||
typename MyBoostSet::iterator bs_e = boostset->end();
|
||||
typename MyStdSet::iterator ss_b = stdset->begin();
|
||||
typename MyStdSet::iterator ss_e = stdset->end();
|
||||
|
||||
std::size_t i = 0;
|
||||
while(bs_b != bs_e){
|
||||
++i;
|
||||
typename MyBoostSet::iterator bs_i;
|
||||
typename MyStdSet::iterator ss_i;
|
||||
//find
|
||||
bs_i = boostset->find(*bs_b);
|
||||
ss_i = stdset->find(*ss_b);
|
||||
if(!CheckEqualIt(bs_i, ss_i, *boostset, *stdset)){
|
||||
return -1;
|
||||
}
|
||||
//lower bound
|
||||
bs_i = boostset->lower_bound(*bs_b);
|
||||
ss_i = stdset->lower_bound(*ss_b);
|
||||
if(!CheckEqualIt(bs_i, ss_i, *boostset, *stdset)){
|
||||
return -1;
|
||||
}
|
||||
//upper bound
|
||||
bs_i = boostset->upper_bound(*bs_b);
|
||||
ss_i = stdset->upper_bound(*ss_b);
|
||||
if(!CheckEqualIt(bs_i, ss_i, *boostset, *stdset)){
|
||||
return -1;
|
||||
}
|
||||
//equal range
|
||||
std::pair<typename MyBoostSet::iterator
|
||||
,typename MyBoostSet::iterator> bs_ip;
|
||||
std::pair<typename MyStdSet::iterator
|
||||
,typename MyStdSet::iterator> ss_ip;
|
||||
bs_ip = boostset->equal_range(*bs_b);
|
||||
ss_ip = stdset->equal_range(*ss_b);
|
||||
if(!CheckEqualIt(bs_ip.first, ss_ip.first, *boostset, *stdset)){
|
||||
return -1;
|
||||
}
|
||||
if(!CheckEqualIt(bs_ip.second, ss_ip.second, *boostset, *stdset)){
|
||||
return -1;
|
||||
}
|
||||
++bs_b;
|
||||
++ss_b;
|
||||
}
|
||||
}
|
||||
//Compare find/lower_bound/upper_bound in multiset
|
||||
{
|
||||
typename MyBoostMultiSet::iterator bm_b = boostmultiset->begin();
|
||||
typename MyBoostMultiSet::iterator bm_e = boostmultiset->end();
|
||||
typename MyStdMultiSet::iterator sm_b = stdmultiset->begin();
|
||||
typename MyStdMultiSet::iterator sm_e = stdmultiset->end();
|
||||
|
||||
while(bm_b != bm_e){
|
||||
typename MyBoostMultiSet::iterator bm_i;
|
||||
typename MyStdMultiSet::iterator sm_i;
|
||||
//find
|
||||
bm_i = boostmultiset->find(*bm_b);
|
||||
sm_i = stdmultiset->find(*sm_b);
|
||||
if(!CheckEqualIt(bm_i, sm_i, *boostmultiset, *stdmultiset)){
|
||||
return -1;
|
||||
}
|
||||
//lower bound
|
||||
bm_i = boostmultiset->lower_bound(*bm_b);
|
||||
sm_i = stdmultiset->lower_bound(*sm_b);
|
||||
if(!CheckEqualIt(bm_i, sm_i, *boostmultiset, *stdmultiset)){
|
||||
return -1;
|
||||
}
|
||||
//upper bound
|
||||
bm_i = boostmultiset->upper_bound(*bm_b);
|
||||
sm_i = stdmultiset->upper_bound(*sm_b);
|
||||
if(!CheckEqualIt(bm_i, sm_i, *boostmultiset, *stdmultiset)){
|
||||
return -1;
|
||||
}
|
||||
//equal range
|
||||
std::pair<typename MyBoostMultiSet::iterator
|
||||
,typename MyBoostMultiSet::iterator> bm_ip;
|
||||
std::pair<typename MyStdMultiSet::iterator
|
||||
,typename MyStdMultiSet::iterator> sm_ip;
|
||||
bm_ip = boostmultiset->equal_range(*bm_b);
|
||||
sm_ip = stdmultiset->equal_range(*sm_b);
|
||||
if(!CheckEqualIt(bm_ip.first, sm_ip.first, *boostmultiset, *stdmultiset)){
|
||||
return -1;
|
||||
}
|
||||
if(!CheckEqualIt(bm_ip.second, sm_ip.second, *boostmultiset, *stdmultiset)){
|
||||
return -1;
|
||||
}
|
||||
++bm_b;
|
||||
++sm_b;
|
||||
}
|
||||
}
|
||||
|
||||
//Now do count exercise
|
||||
boostset->erase(boostset->begin(), boostset->end());
|
||||
boostmultiset->erase(boostmultiset->begin(), boostmultiset->end());
|
||||
|
Reference in New Issue
Block a user