Guest User

Untitled

a guest
May 26th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
  4.  
  5. public class Stupid {
  6.  
  7. public static void run() {
  8. for(int N = 32; N<=1048576;N*=2) {
  9. int[] x = new int[N];
  10. Random rand = new Random();
  11. for(int k = 0;k < N; ++k) x[k]=rand.nextInt();
  12. Arrays.sort(x);
  13. HashSet<Integer> hs = new HashSet<Integer>();
  14. for(int k = 0;k < N; ++k) hs.add(x[k]);
  15. TreeSet<Integer> ts = new TreeSet<Integer>();
  16. for(int k = 0;k < N; ++k) ts.add(x[k]);
  17. IntOpenHashSet ohs = new IntOpenHashSet();
  18. for(int k = 0; k < N; ++k) ohs.add(x[k]);
  19. int howmanyqueries = 1000000;
  20. int[] whichvalues = new int[howmanyqueries];
  21. for(int k = 0;k<howmanyqueries; ++k)
  22. whichvalues[k] = rand.nextInt();
  23. long aft1 = System.currentTimeMillis();
  24. for(int t=1;t<10;++t) for(int wv : whichvalues) Arrays.binarySearch(x,wv);
  25. long aft2 = System.currentTimeMillis();
  26. for(int t=1;t<10;++t) for(int wv : whichvalues) hs.contains(wv);
  27. long aft3 = System.currentTimeMillis();
  28. for(int t=1;t<10;++t) for(int wv : whichvalues) ts.contains(wv);
  29. long aft4 = System.currentTimeMillis();
  30. for(int t=1;t<10;++t) for(int wv : whichvalues) ohs.contains(wv);
  31. long aft5 = System.currentTimeMillis();
  32. System.out.println(N+" "+(aft2-aft1)/(1000.0*howmanyqueries)+ " "+(aft3-aft2)/(1000.0*howmanyqueries)+ " "+(aft4-aft3)/(1000.0*howmanyqueries) + " "+(aft5-aft4)/(1000.0*howmanyqueries));
  33. }
  34. }
  35.  
  36. public static void main(String [] a) {
  37. run();
  38. }
  39. }
  40.  
  41. /*
  42. * 32 2.66E-7 3.62E-7 4.68E-7 2.71E-7
  43. 64 3.55E-7 3.77E-7 6.01E-7 3.29E-7
  44. 128 4.31E-7 3.83E-7 6.7E-7 2.83E-7
  45. 256 4.67E-7 3.63E-7 7.25E-7 2.96E-7
  46. 512 5.6E-7 4.05E-7 8.38E-7 2.66E-7
  47. 1024 5.79E-7 3.76E-7 9.37E-7 2.63E-7
  48. 2048 6.31E-7 3.8E-7 1.049E-6 2.62E-7
  49. 4096 6.71E-7 4.99E-7 1.418E-6 3.03E-7
  50. 8192 8.06E-7 4.53E-7 1.609E-6 2.65E-7
  51. 16384 8.12E-7 4.81E-7 1.913E-6 2.79E-7
  52. 32768 9.14E-7 6.43E-7 2.541E-6 2.85E-7
  53. 65536 1.025E-6 9.12E-7 4.414E-6 3.06E-7
  54. 131072 1.497E-6 1.362E-6 6.515E-6 3.4E-7
  55. 262144 1.703E-6 1.727E-6 8.585E-6 3.67E-7
  56. 524288 2.155E-6 1.828E-6 1.0578E-5 5.51E-7
  57. 1048576 2.867E-6 1.998E-6 1.2602E-5 7.88E-7
  58. */
Add Comment
Please, Sign In to add comment