Created
April 15, 2014 21:18
-
-
Save Kojirion/10776248 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Output: | |
0.000019s wall, 0.000000s user + 0.000000s system = 0.000000s CPU (n/a%) | |
0.000029s wall, 0.000000s user + 0.000000s system = 0.000000s CPU (n/a%) | |
0.000019s wall, 0.000000s user + 0.000000s system = 0.000000s CPU (n/a%) | |
0.000019s wall, 0.000000s user + 0.000000s system = 0.000000s CPU (n/a%) | |
0.000019s wall, 0.000000s user + 0.000000s system = 0.000000s CPU (n/a%) | |
*/ | |
#include <boost/range/algorithm_ext/iota.hpp> | |
#include <boost/range/algorithm/find.hpp> | |
#include <boost/algorithm/cxx11/any_of.hpp> | |
#include <boost/timer/timer.hpp> | |
#include <functional> | |
using std::placeholders::_1; | |
template<typename InputIterator, typename V> | |
bool improved_any_of_equal ( InputIterator first, InputIterator last, const V &val ) | |
{ | |
return std::find(first, last, val) != last; | |
} | |
int main() | |
{ | |
std::vector<int> foo(100000); | |
boost::iota(foo, 0); | |
bool found_1, found_2, found_3, found_4, found_5; | |
int toLookFor = 49000; | |
//boost::find | |
{ | |
boost::timer::auto_cpu_timer timer; | |
found_1 = (boost::find(foo, toLookFor) != foo.end()); | |
} | |
//current any_of_equal | |
{ | |
boost::timer::auto_cpu_timer timer; | |
found_2 = boost::algorithm::any_of_equal(foo, toLookFor); | |
} | |
//std::find | |
{ | |
boost::timer::auto_cpu_timer timer; | |
found_3 = (std::find(foo.begin(), foo.end(), toLookFor) != foo.end()); | |
} | |
//c++11 std::any_of | |
{ | |
boost::timer::auto_cpu_timer timer; | |
found_4 = std::any_of(foo.begin(), foo.end(), std::bind(std::equal_to<int>(), toLookFor, _1)); | |
} | |
//proposed any_of_equal | |
{ | |
boost::timer::auto_cpu_timer timer; | |
found_5 = improved_any_of_equal(foo.begin(), foo.end(), toLookFor); | |
} | |
std::cout << std::boolalpha << found_1 << '\n' | |
<< found_2 << '\n' | |
<< found_3 << '\n' | |
<< found_4 << '\n' | |
<< found_5 << '\n'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment