Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package MY_Test_ASD.TestArrrayList;
  7.  
  8. import java.util.ArrayList;
  9.  
  10. /**
  11. *
  12. * @author Student
  13. */
  14. public class Arraylist {
  15.  
  16.  
  17. public long testWstawLinie(int liczbaElem){
  18.  
  19. long czasStart=System.currentTimeMillis();
  20.  
  21. ArrayList<String> list= new ArrayList();
  22.  
  23. for(int i=0; i<liczbaElem; i++){
  24. list.add("Ala");
  25. }
  26.  
  27. long czasStop=System.currentTimeMillis();
  28.  
  29. return czasStop-czasStart;
  30.  
  31. }
  32.  
  33. public long testPrzegladania(int liczbaElem, int liczbaPrzegladow){
  34.  
  35. ArrayList<String> list= new ArrayList();
  36.  
  37. for(int i=0; i<liczbaElem; i++){
  38. list.add("Ala");
  39. }
  40.  
  41. long czasStart=System.currentTimeMillis();
  42. //------------------------------------------------------------------
  43.  
  44. for(int i=0; i<liczbaPrzegladow; i++){
  45. for(int j=0; j<liczbaElem; j++){
  46. String elem=list.get(i);
  47. }
  48. }
  49.  
  50. //------------------------------------------------------------------
  51. long czasStop=System.currentTimeMillis();
  52.  
  53. return czasStop-czasStart;
  54.  
  55. }
  56.  
  57. public long testUsuwania(long liczbaElem){
  58.  
  59.  
  60. long czasStart=System.currentTimeMillis();
  61.  
  62. ArrayList<String> list= new ArrayList();
  63.  
  64. for(int i=0; i<liczbaElem; i++){
  65. list.add("Ala");
  66. }
  67.  
  68. for(int i=list.size()-1; i>0; i--)
  69. {
  70. list.remove(i);
  71. }
  72.  
  73.  
  74. long czasStop=System.currentTimeMillis();
  75.  
  76. return czasStop-czasStart;
  77.  
  78.  
  79.  
  80.  
  81.  
  82. }
  83.  
  84. public static void main(String [] args){
  85. Arraylist test=new Arraylist();
  86.  
  87. long czas=test.testWstawLinie(100000000);
  88.  
  89. System.out.println("czas wstawiania="+czas);
  90.  
  91. long czasPrzegladania=test.testPrzegladania(100000000, 5);
  92.  
  93. System.out.println("czas przegladania="+czasPrzegladania);
  94.  
  95.  
  96. long czasUsuwania=test.testUsuwania(100000000);
  97.  
  98. System.out.println("czas usuwania="+czasUsuwania);
  99. }
  100.  
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement