Advertisement
Guest User

Untitled

a guest
Apr 28th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. package com.google.caliper.timsort;
  2. import com.google.caliper.timsort.SortingAlgorithms;
  3.  
  4. import java.util.Random;
  5.  
  6. import com.google.caliper.AfterExperiment;
  7. import com.google.caliper.BeforeExperiment;
  8. import com.google.caliper.Benchmark;
  9.  
  10. public final class TimsortBenchmark {
  11.     Random rand = new Random(0607);
  12.     Integer[] tab = new Integer[64];
  13.     Integer[] temp;
  14.    
  15.     @BeforeExperiment void setUp() {
  16.         tab[0] = 1;
  17.         for(int i = 1; i < tab.length; i++){
  18.             tab[i] = rand.nextInt();
  19.             //tab[i] = tab[i - 1] - 20 + (rand.nextInt(100 - 1 + 1) + 1);
  20.         }
  21.         temp = new Integer[2 * tab.length];
  22.     }
  23.    
  24.     @AfterExperiment void tearDown(){
  25.         tab = null;
  26.         temp = null;
  27.     }
  28.    
  29.      @Benchmark void binarySort(int reps) {
  30.         for (int i = 0; i < reps; i++) {
  31.             SortingAlgorithms.binarySort(tab);
  32.         }
  33.     }
  34.    
  35.     @Benchmark void insertSort(int reps) {
  36.         for (int i = 0; i < reps; i++) {
  37.             SortingAlgorithms.insertSort(tab, temp);
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement