perf_discrete_distribution.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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/discrete_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<compute::uint_> vector(PERF_N, context);
  27. int weights[] = {1, 1};
  28. compute::default_random_engine rng(queue);
  29. compute::discrete_distribution<compute::uint_> dist(weights, weights+2);
  30. perf_timer t;
  31. t.start();
  32. dist.generate(vector.begin(), vector.end(), rng, queue);
  33. queue.finish();
  34. t.stop();
  35. std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
  36. return 0;
  37. }