일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- bytecode
- 여행계획
- 일상회피
- ㅇ
- 회피
- Transition
- javap
- static
- 버킷리스트
- 보안취약점
- Android
- Shared Elements
- 취약점
- 여행
- IMPLEMENT
- jvm
- bytecode 분석
- extends
- HelloWorld
- opcode
- 심리여행
- 보안
- Interface
- 일상탈출
- Recylcer
- 심리학
- Navigation Component
- 치유
- abstract
- throws
- Today
- Total
패스트터틀
(performance) about performance in Java Language 본문
(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)
2) String -> StringBuffer(동기화), StringBuilder(비동기화일때)
3) << n ==> *2^n , >> n ==> /2^n ( use shift)
4)
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(....);
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.
'Development language > java' 카테고리의 다른 글
Java 에서 "Hello World" 가 출력되기까지의 과정 (0) | 2022.06.12 |
---|---|
(basic) abstract, interface, implement, extends, throws ... (0) | 2020.01.24 |
(basic) java개념, Buffer, new, Generic, sort, 동적 .... (0) | 2019.11.06 |