perf_bernoulli_distribution.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2014 Roshan <thisisroshansmail@gmail.com>
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. // See http://boostorg.github.com/compute for more information.
  9. //---------------------------------------------------------------------------//
  10. #include <algorithm>
  11. #include <iostream>
  12. #include <vector>
  13. #include <boost/compute/system.hpp>
  14. #include <boost/compute/container/vector.hpp>
  15. #include <boost/compute/random/default_random_engine.hpp>
  16. #include <boost/compute/random/bernoulli_distribution.hpp>
  17. #include "perf.hpp"
  18. namespace compute = boost::compute;
  19. int main(int argc, char *argv[])
  20. {
  21. perf_parse_args(argc, argv);
  22. std::cout << "size: " << PERF_N << std::endl;
  23. compute::device device = compute::system::default_device();
  24. compute::context context(device);
  25. compute::command_queue queue(context, device);
  26. compute::vector<bool> vector(PERF_N, context);
  27. compute::default_random_engine rng(queue);
  28. compute::bernoulli_distribution<float> dist(0.5);
  29. perf_timer t;
  30. t.start();
  31. dist.generate(vector.begin(), vector.end(), rng, queue);
  32. queue.finish();
  33. t.stop();
  34. std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
  35. return 0;
  36. }