SHARE
TWEET

Untitled

a guest Feb 18th, 2020 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import java.io.FileNotFoundException;
  3. import java.io.FileReader;
  4. import java.util.ArrayList;
  5. import java.util.Collections;
  6. import java.util.List;
  7. import java.util.Scanner;
  8.  
  9. public class PerformanceAnalysis {
  10.  
  11.  
  12.     static Scanner fileHandler() throws FileNotFoundException {
  13.         // csv File location
  14.  
  15.         String filepath = "test_data.csv";
  16.  
  17.  
  18.         // opens the file provided by user
  19.         FileReader fr = new FileReader(filepath);
  20.  
  21.         // reads the file
  22.         Scanner source = new Scanner(fr);
  23.  
  24.     return source;
  25.     }
  26.  
  27.     static void performanceTestingArrayDirectory() throws FileNotFoundException {
  28.         ArrayList<Long> averageInsertList = new ArrayList<Long>();
  29.         ArrayList<Long> worseInsertList = new ArrayList<Long>();
  30.         ArrayList<Long> bestInsertList = new ArrayList<Long>();
  31.  
  32.  
  33.  
  34.         StopWatch watch = new StopWatch();
  35.  
  36.         // Creates an ArrayDirectory object
  37.         ArrayDirectory muhammed = new ArrayDirectory();
  38.  
  39.  
  40.         Scanner source = fileHandler();
  41.  
  42.  
  43.         // insert test
  44.         for (int i = 0; i < 1000; i++) {
  45.             List<Long> elapsedTime = new ArrayList<Long>();
  46.  
  47.             // while the source has lines to read
  48.             while (source.hasNext()) {
  49.  
  50.                 // splits each line with commas and put them into a string array
  51.                 String[] s = source.nextLine().split(",");
  52.  
  53.                 // checks if the extension length is correct
  54.                 if (s[2].length() == 5) {
  55.  
  56.  
  57.                     // new object is created for each new entry. using their surnames, initials, and extension
  58.                     watch.reset();
  59.                     watch.start();
  60.  
  61.                     muhammed.insertEntry(new Entry(s[0], s[1], s[2]));
  62.                     watch.stop();
  63.                     elapsedTime.add(watch.getElapsedTime());
  64.  
  65.  
  66.                     long sum = 0;
  67.                     for (long time : elapsedTime) {
  68.                         sum = sum + time;
  69.  
  70.  
  71.                     }
  72.                     long worstInsertArrayDirectory = Collections.min(elapsedTime);
  73.                     long bestInsertArrayDirectory = Collections.max(elapsedTime);
  74.                     long averageInsertArrayDirectory = (sum / elapsedTime.size());
  75.  
  76.  
  77.                     bestInsertList.add(bestInsertArrayDirectory);
  78.                     worseInsertList.add(worstInsertArrayDirectory);
  79.                     averageInsertList.add(averageInsertArrayDirectory);
  80.  
  81.  
  82.                 }
  83.  
  84.  
  85.             }
  86.  
  87.  
  88.         }
  89.  
  90.         long sum1 = 0;
  91.         for (Long time : averageInsertList) {
  92.             sum1 = sum1 + time;}
  93.         System.out.println(Collections.min(worseInsertList));
  94.         System.out.println((sum1/averageInsertList.size()));
  95.             System.out.println(Collections.max(bestInsertList));
  96.         }
  97.  
  98.  
  99.  
  100.  
  101.     static void performanceTestingArrayListDirectory() throws FileNotFoundException {
  102.  
  103.         List<Long> elapsedTime = new ArrayList<Long>();
  104.  
  105.         StopWatch watch = new StopWatch();
  106.  
  107.  
  108.         // Creates an ArrayDirectory object
  109.         ArrayListDirectory muhammed = new ArrayListDirectory();
  110.  
  111.         Scanner source = fileHandler();
  112.  
  113.  
  114.         // while the source has lines to read
  115.         while (source.hasNext()) {
  116.  
  117.             // splits each line with commas and put them into a string array
  118.             String[] s = source.nextLine().split(",");
  119.  
  120.             // checks if the extension length is correct
  121.             if (s[2].length() == 5) {
  122.  
  123.  
  124.                 // new object is created for each new entry. using their surnames, initials, and extension
  125.                 watch.reset();
  126.                 watch.start();
  127.  
  128.                 muhammed.insertEntry(new Entry(s[0], s[1], s[2]));
  129.                 watch.stop();
  130.                 elapsedTime.add(watch.getElapsedTime());
  131.  
  132.  
  133.             }
  134.  
  135.  
  136.         }
  137.         double sum = 0;
  138.         for (long time : elapsedTime) {
  139.             sum = sum + time;
  140.  
  141.  
  142.         }
  143.         long worstInsertArrayListDirectory = Collections.min(elapsedTime);
  144.         long bestInsertArrayListDirectory = Collections.max(elapsedTime);
  145.         double averageInsertArrayListDirectory = (sum / elapsedTime.size());
  146.  
  147.  
  148.         System.out.println(worstInsertArrayListDirectory);
  149.         System.out.println(bestInsertArrayListDirectory);
  150.         System.out.println(averageInsertArrayListDirectory);
  151.  
  152.  
  153. }
  154.  
  155.     static void performanceTestingHashMapDirectory () throws FileNotFoundException {
  156.  
  157.  
  158.         List<Long> elapsedTime = new ArrayList<Long>();
  159.  
  160.         StopWatch watch = new StopWatch();
  161.  
  162.         // csv File location
  163.  
  164.  
  165.         // Creates an ArrayDirectory object
  166.         ArrayListDirectory muhammed = new ArrayListDirectory();
  167.  
  168.  
  169.         Scanner source = fileHandler();
  170.  
  171.  
  172.         // while the source has lines to read
  173.         while (source.hasNext()) {
  174.  
  175.             // splits each line with commas and put them into a string array
  176.             String[] s = source.nextLine().split(",");
  177.  
  178.             // checks if the extension length is correct
  179.             if (s[2].length() == 5) {
  180.  
  181.  
  182.                 // new object is created for each new entry. using their surnames, initials, and extension
  183.                 watch.reset();
  184.                 watch.start();
  185.  
  186.                 muhammed.insertEntry(new Entry(s[0], s[1], s[2]));
  187.                 watch.stop();
  188.                 elapsedTime.add(watch.getElapsedTime());
  189.  
  190.  
  191.             }
  192.  
  193.  
  194.         }
  195.         double sum = 0;
  196.         for (long time : elapsedTime) {
  197.             sum = sum + time;
  198.  
  199.  
  200.         }
  201.         long worstInsertArrayListDirectory = Collections.min(elapsedTime);
  202.         long bestInsertArrayListDirectory = Collections.max(elapsedTime);
  203.         double averageInsertArrayListDirectory = (sum / elapsedTime.size());
  204.  
  205.  
  206.         System.out.println(worstInsertArrayListDirectory);
  207.         System.out.println(bestInsertArrayListDirectory);
  208.         System.out.println(averageInsertArrayListDirectory);
  209.  
  210.  
  211.  
  212.     }
  213.  
  214.  
  215.     public static void main (String[] args) throws FileNotFoundException {
  216.  
  217.          performanceTestingArrayDirectory();
  218.         System.out.println("========================");
  219. //        performanceTestingArrayListDirectory();
  220. //        System.out.println("===================");
  221. //        performanceTestingHashMapDirectory();
  222.     }
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top