패스트터틀

(performance) about performance in Java Language 본문

Development language/java

(performance) about performance in Java Language

SudekY 2019. 11. 10. 13:17

 본 포스팅은 블로거가 개발언어의 개념정리 필요를 위한것입니다.

목차와 차례가 뒤죽박죽이며 오직 블로거의 편의목적을 위해 작성되었음을 알려드립니다. 

 

- basic

- array vs arraylist vs list

- Separation(Scanner,split,tokenizer)

- Scanner vs BufferedReader

 

 

- basic

 

1)

 

왜 자바에서 static의 사용을 지양해야 하는가?

자바에서 데이터를 가공하거나 특정 메서드를 수행할 때 새로운 클래스를 만들어서 이를 인스턴스화 해서 쓸건지 아니면 static 으로 쓸건지 고민하게 될 때가 있다. 사실 후자는 객체지향적 관점에서 그리 좋은..

unabated.tistory.com

2) String -> StringBuffer(동기화), StringBuilder(비동기화일때)

3) << n  ==> *2^n   , >> n ==> /2^n ( use shift)

4) 

 

자바 어플리케이션의 성능 향상

올바른 코딩 규칙, 클래스의 올바른 사용을 통해 성능 저하 요소를 없앨 수 있으며 오브젝트 풀링을 함께 사용함으로써 어플리케이션의 전체적인 성능을 향상시킬 수 있다. 자바와 성능 문제 오늘날 자바는 엔터프..

javacan.tistory.com

 

5)

 

 

- array vs arraylist vs list

from stackoverflow...

Array is faster and that is because ArrayList uses a fixed amount of array.
However when you add an element to the ArrayList and it overflows. It creates a new Array and copies every element from the old one to the new one.
You will only feel this if you add to often.

 

Since the add from ArrayList is O(n) and the add to the Array is O(1).


However because ArrayList uses an Array is faster to search O(1) in it than normal lists O(n).

 

arraylist는 array에 추가적으로 붙혀지는것이라 add 속도는 O(n) array는 O(1)이다.

하지만 normal list 에서는 O(1)로 검색에서 더 빠르다.

 

 

- Separation(Scanner,split,tokenizer)

from stackoverflow...

1) String[] array = str.split("#");

2) str.substring(3);

3) Stringtokenzier st = new Stringtokenzier(....);

 

 

 

https://www.javamex.com/tutorials/regular_expressions/splitting_tokenisation_performance.shtml

1) From this point of view, StringTokenizer is a bit of a waste of space nowadays, and you may as well just use String.split().

 

stackoverflow 에서도 상당수가 stringtokenizer 를 사용하지 말라고 한다.

그다지 큰 차이가 없을뿐만 아니라 공식 document 에서도 split을 사용하라고 한다.

 

Personally, the only time I can remember using Scanner is for school projects, when I had to get user input from the command line. It makes that sort of operation easy. But if I have a String that I want to split up, it's almost a no-brainer to go with split().

 

그밖에도 학교 프로젝트에서 커멘드라인에 입력받는 경우가아니라면 string으로 받아서 split을 사용하라고 권고한다.

 

- Scanner vs BufferedReader

from stackoverflow...

As to the choice, use the Scanner if you want to parse the file, use the BufferedReader if you want to read the file line by line. Also see the introductory text of their aforelinked API documentations.

  • Parsing = interpreting the given input as tokens (parts). It's able to give back you specific parts directly as int, string, decimal, etc. See also all those nextXxx() methods in Scanner class.
  • Reading = dumb streaming. It keeps giving back you all characters, which you in turn have to manually inspect if you'd like to match or compose something useful. But if you don't need to do that anyway, then reading is sufficient.

 

Comments