Code for a blogpost
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
1006 B

  1. package net.jrtechs;
  2. import java.util.Vector;
  3. public class GenericTester<E>
  4. {
  5. public long timeTrialMS(ParallelExecutor<E> executor, Vector<Work<E>> tasks)
  6. {
  7. long start = System.nanoTime();
  8. executor.runTasks(tasks);
  9. long finish = System.nanoTime();
  10. return (finish-start)/1000000;
  11. }
  12. public Result testAll(Vector<Work<E>> tasks)
  13. {
  14. ParallelExecutor<E> streams = new ParallelStreamsExecutor<>();
  15. ParallelExecutor<E> threads = new RunThreads<>();
  16. ParallelExecutor<E> manager = new Manager<>(8);
  17. ParallelExecutor<E> single = new SingleThread<>();
  18. ParallelExecutor<E> pool = new ThreadPoolExecutor<>();
  19. Result res = new Result();
  20. res.streams = timeTrialMS(streams, tasks);
  21. res.manager = timeTrialMS(manager, tasks);
  22. res.threads = timeTrialMS(threads, tasks);
  23. res.pool = timeTrialMS(pool, tasks);
  24. res.singleThread = timeTrialMS(single, tasks);
  25. return res;
  26. }
  27. }