11 템플릿적용 - Java Program Performance Tuning (김명호기술이사)

Similar documents
07 자바의 다양한 클래스.key

ilist.add(new Integer(1))과 같이 사용하지 않고 ilist.add(1)과 같이 사용한 것은 자바 5.0에 추가된 기본 자료형과 해당 객체 자료 형과의 오토박싱/언박싱 기능을 사용한 것으로 오토박싱이란 자바 컴파일러가 객체를 요구하는 곳에 기본 자료형

02 C h a p t e r Java

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

신림프로그래머_클린코드.key

PowerPoint 프레젠테이션


OOP 소개

1

PowerPoint 프레젠테이션

화판_미용성형시술 정보집.0305

교육자료

09-interface.key

Java

rmi_박준용_final.PDF


비긴쿡-자바 00앞부속

K&R2 Reference Manual 번역본

NoSQL

Mobile Service > IAP > Android SDK [ ] IAP SDK TOAST SDK. IAP SDK. Android Studio IDE Android SDK Version (API Level 10). Name Reference V

11강-힙정렬.ppt

자바 프로그래밍

MasoJava4_Dongbin.PDF

목차 INDEX JSON? - JSON 개요 - JSONObject - JSONArray 서울시공공데이터 API 살펴보기 - 요청인자살펴보기 - Result Code - 출력값 HttpClient - HttpHelper 클래스작성 - JSONParser 클래스작성 공공

untitled

Microsoft Word - java19-1-midterm-answer.doc

JMF3_심빈구.PDF

PowerPoint Presentation

C# Programming Guide - Types

05-class.key

5장.key

12-file.key

Secure Programming Lecture1 : Introduction

3ÆÄÆ®-11

2014_트렌드씨_웹용_1월_s

Index

: 1 int arr[9]; int n, i; printf(" : "); scanf("%d", &n); : : for(i=1; i<10; i++) arr[i-1] = n * i; for(i=0; i<9; i++) if(i%2 == 1) print

어댑터뷰

KARAAUTO_4¿ù.qxd-ÀÌÆå.ps, page Normalize

PowerPoint Presentation

3ÆÄÆ®-14

public key private key Encryption Algorithm Decryption Algorithm 1

강의10

chap10.PDF

Microsoft PowerPoint - 04-UDP Programming.ppt

2014밝고고운동요부르기-수정3

2005프로그램표지

Modern Javascript

03장.스택.key

Java XPath API (한글)

10주차.key

4장.문장

A Tour of Java V

ch09

03-JAVA Syntax(2).PDF

Chap12

FileMaker ODBC and JDBC Guide

슬라이드 1

I T C o t e n s P r o v i d e r h t t p : / / w w w. h a n b i t b o o k. c o. k r

프로그램을 학교 등지에서 조금이라도 배운 사람들을 위한 프로그래밍 노트 입니다. 저 역시 그 사람들 중 하나 입니다. 중고등학교 시절 학교 도서관, 새로 생긴 시립 도서관 등을 다니며 책을 보 고 정리하며 어느정도 독학으르 공부하긴 했지만, 자주 안하다 보면 금방 잊어

歯9장.PDF

2

Week5

01-OOPConcepts(2).PDF

example code are examined in this stage The low pressure pressurizer reactor trip module of the Plant Protection System was programmed as subject for

Microsoft Word - ExecutionStack

PowerPoint Presentation

6주차.key

Microsoft PowerPoint - Java7.pptx

2

초보자를 위한 C# 21일 완성

Analytics > Log & Crash Search > Unity ios SDK [Deprecated] Log & Crash Unity ios SDK. TOAST SDK. Log & Crash Unity SDK Log & Crash Search. Log & Cras

歯JavaExceptionHandling.PDF

JUNIT 실습및발표

Interstage5 SOAP서비스 설정 가이드

FileMaker ODBC and JDBC Guide

PowerPoint Presentation

thesis-shk

Microsoft PowerPoint - CSharp-10-예외처리

Contents Contents 2 1 Abstract 3 2 Infer Checkers Eradicate Infer....

C++-¿Ïº®Çؼ³10Àå

untitled

Design Issues

Runtime Data Areas 엑셈컨설팅본부 /APM 팀임대호 Runtime Data Area 구조 Runtime Data Area 는 JVM 이프로그램을수행하기위해할당받는메모리영역이라고할수있다. 실제 WAS 성능문제에직면했을때, 대부분의문제점은 Runtime Da

untitled

* Factory class for query and DML clause creation * tiwe * */ public class JPAQueryFactory implements JPQLQueryFactory private f

Microsoft PowerPoint - ch09 - 연결형리스트, Stack, Queue와 응용 pm0100

JMF2_심빈구.PDF

개발을 통한 자기수양

chap 5: Trees

Spring Boot/JDBC JdbcTemplate/CRUD 예제

MS-SQL SERVER 대비 기능

Microsoft PowerPoint 자바-기본문법(Ch2).pptx

Chap7.PDF

C++ Programming

PowerPoint Presentation

Semantic Consistency in Information Exchange

스레드의우선순위 우선순위설정메소드 : void setpriority(int newpriority) newpriority 에설정할수있는등급 : 1( 가장낮은우선순위 ) 부터 10( 가장높은우선순위 ) 가장높은우선순위 : MAX_PRIORITY, 보통우선순위 : NORM_

gnu-lee-oop-kor-lec11-1-chap15

Transcription:

Java Program Performance Tuning

( )

n (Primes0) static List primes(int n) { List primes = new ArrayList(n); outer: for (int candidate = 2; n > 0; candidate++) { Iterator iter = primes.iterator(); while (iter.hasnext()) { int aprime = ((Integer)iter.next()).intValue(); if (candidate%aprime == 0) continue outer; } primes.add(new Integer(candidate)); n--; } return primes; }

System.currentTimeMillis() long starttime = System.currentTimeMillis(); //... long duration = System.currentTimeMillis() - starttime; java Primes0 count count? 100: 0 ms count = 1,000: 170 ms count = 10,000: 15,320 ms count = 100,000: 5,850,320 ms

java -verbosegc [GC 511K->158K(1984K), 0.0061533 secs] [GC 670K->190K(1984K), 0.0030096 secs] [GC 702K->220K(1984K), 0.0023509 secs] [GC 732K->249K(1984K), 0.0040178 secs] [GC 761K->278K(1984K), 0.0033440 secs]...

( ) java -Xbootclasspath/p:object.jar Primes0 10000 java.lang.integer 10,000 java.util.arraylist 1 java.util.abstractlist$itr 104,728

( ) Runtime totalmemory(), freememory()

java Xrunhprof:cpu=samples CPU SAMPLES BEGIN (total = 659) Sun Jan 20 20:23:05 2002 rank self accum count trace method 1 49.01% 49.01% 323 13 Primes0.primes 2 21.55% 70.56% 142 12 java.util.abstractlist$itr.next 3 7.74% 78.30% 51 11 java.util.arraylist.get 4 7.44% 85.74% 49 14 Primes0.primes 5 7.28% 93.02% 48 9 Primes0.primes 6 4.55% 97.57% 30 15 java.util.abstractlist$itr.hasnext 7 1.06% 98.63% 7 10 java.util.abstractlist.iterator 8 0.15% 98.79% 1 16 Primes0.primes 2 70%

( ) TRACE 13 //while (iter.hasnext())... Primes0.primes(Primes0.java:22) Primes0.main(Primes0.java:9) TRACE 12 //int aprime = ((Integer)iter.next()).intValue(); java.util.abstractlist$itr.next(<unknown>:unknown line) Primes0.primes(Primes0.java:23) Primes0.main(Primes0.java:9)

Primes0 while. Primes0 if (aprime*aprime > candidate) break; [Not if (aprime > (int)math.sqrt(candidate)) break;]

n (Primes1) static List primes(int n) { List primes = new ArrayList(n); outer: for (int candidate = 2; n > 0; candidate++) { Iterator iter = primes.iterator(); while (iter.hasnext()) { int aprime = ((Integer)iter.next()).intValue(); //Applying better algorithm if (aprime*aprime > candidate) break; if (candidate % k == 0) continue outer; } primes.add(new Integer(candidate)); n--; } return primes; }

Primes1 (java Primes1 count) count? 100: 0 ms (vs. 0 ms) count = 1,000: 50 ms (vs. 170 ms) count = 10,000: 220 ms (vs. 15,320 ms) count = 100,000: 4,450 ms (vs. 5,850,320 ms) Primes0 Integer, Iterator(Itr)

HotSpot VM ( ), (adaptive optimization) JIT JIT

javac javac String final (= ) : HotSpot VM -O

,,!

(strength reduction) : 0 for (int i = 0; i < size; i++) for (int i = size-1; i >= 0; i--) (code motion) : llist l.size() for (int i = 0; i < l.size(); i++) for (int i = 0, lsize = l.size(); i < lsize; i++)

( ) int max_a = 100; final int max_a = 100; int max_b = 200; final int max_b = 200; for (int i = arr.length 1; i >= 0; i--) arr[i] = max_a + max_b; final arr[i] = max_a + max_b; arr[i] = 300;

class Poor { int field = 0; public Poor() { field = 0; } } //field is initialized 3 times! data = new int[items]; for (int i = 0; i < items; i++) data[i] = 0; //redundant initialization

( ) MyData data[]; data[m+n].doit(a+1); data[m+n].doit(a+2); MyData dmn = data[m+n]; dmn.doit(a+1); dmn.doit(a+2); data[m+n].doit(a+1).doit(a+2);

( ) ArrayList.get(int index) rangecheck(index); return elementdata[index]; ArrayList.rangeCheck(int index) if (index >= size index < 0) //check once throw new IndexOutOfBoundsException( ); //redundant check

( ) API new Integer( 100 ).intvalue() Integer.parseInt( 100 ) // /

StringStringBuffer! String str = Hello + world! ; String str = Hello world! ; //!

StringStringBuffer ( ) String str = a + b; // String str =new StringBuffer(). append(a).append(b).tostring(); String str = ; StringBuffer sbuf = for ( ) new StringBuffer( ); str += ; for ( ) sbuf.append( ); String str = sbuf.tostring(); StringBuffer

StringStringBuffer 0;1;2...;n (ms) n <=100 1,000 10,000 100,000 String 0 280 26,530 6,833,940 StringBuffer 0 50 110 1,150 String: 3*n +? vs. StringBuffer: n +?

fillinstacktrace() if ( ) Exception EXCEPTION = throw new Exception( ); new Exception( ); if ( ) if ( ) throw EXCEPTION; throw new Exception( ); if ( ) throw EXCEPTION;

((HasXYZ)obj).x + ((HasXYZ)obj).y + ((HasXYZ)obj).z HasXYZ xyz = (HasXYZ)obj; xyz.x + xyz.y + xyz.z

/ null, for (int i = 0; i < REPEAT; i++) counts[0] += i; int acount = counts[0]; for (int i = 0; i < REPEAT; i++) acount += i; counts[0] = acount;

n (Primes2) //Using specialized collection static intlist primes(int n) { intlist primes = new intlist(n); outer: for (int candidate = 2; n > 0; candidate++) { final int size = primes.size(); //Indexing r.t. Enumeration for (int i = 0; i < size; i++) { int aprime = primes.get(i);//no cast if (aprime * aprime > candidate) break; if (candidate % k == 0) continue outer; } primes.add(candidate);//no object creation n--; } return primes; }

n (Primes2 ) class intlist { private int[] data; private int size, capacity; } public intlist(int capacity) { data = new int[capacity]; this.capacity = capacity; } public int get(int index) { //No redundant checks, no cast return data[index]; } public int size() { return size; } public void add(int value) { data[size++] = value; }

n (Primes3) //Using array instead of collection static int[] primes(int n) { int[] primes = new int[n]; int spot = 0; outer: for (int candidate = 2; n > 0; candidate++) { for (int i = 0; i < spot; i++) { int k = primes[i]; //No method calls, no indirection if (k * k > candidate) break; if (candidate % k == 0) continue outer; } primes[spot++] = candidate; n--; } return primes; }

Primes0-3 100,000 (ms)

Primes1-3 100,000 (ms)

Primes0-3 Primes0, Primes1 java.lang.integer 100,000 java.util.arraylist 1 java.util.abstractlist$itr 1,299,708 Primes2 intlist 1 Primes3 None! --Hurrah!

Primes0-3