Site Search :
Standard Enterprise XML Methodology Pattern Setting Tunning Other
Article Contributors
GuestBook
Javapattern Maven
XSourceGen Dev
JetSpeed Test
JLook Image
jLook Family Site


StringBuffer class Optimization
 
StringBufferŬ·¡½º ¹üÁÖ¿¡¼­µµ ÃÖÀûÈ­½Ãų¼ö ÀÖ´Â ¹æ¾ÈÀ» ¸ð»öÇغ»´Ù. ( 2003/02/28 ) 113
Written by ienvyou - ÃÖÁö¿õ
1 of 1
 

¿©±â¼­´Â StringBufferŬ·¡½ºÀÇ ¼º´ÉÀ» ¿Ã¸®´Â ¹æ¹ý¿¡ ´ëÇÏ¿© ¾Ë¾Æº¸µµ·Ï ÇÏÀÚ.
ÀϹÝÀûÀ¸·Î StringBuffer´Â dafaultÅ©±â·Î ½ÃÀÛÇÏ¿© »õ·Î¿î ½ºÆ®¸µÀ̳ª ¹®ÀÚ°ªÀÌ 
ÀԷµǾúÀ» °æ¿ì, ¹öÆÛ¿¡ °è¼Ó Ãß°¡½ÃÅ°´Â ´Ü°è¸¦ ¹Ýº¹ÇÑ´Ù.

J2SDK 1.3¹öÀü¿¡¼­´Â ÀÌ StringBufferŬ·¡½ºÀÇ ÃʱâÅ©±â¸¦ 16À¸·Î ½ÃÀÛÇÏ°Ô²û ¼³°èÇسõ¾Ò´Ù. 
ÀÌ Å©±â´Â StringBufferÀÇ Çѵµ°¡ ÃÊ°úµÇ´Â ½Ã°£¿¡ ¹öÆÛ°¡ Áõ°¡(»õ·Î appendµÇ¾úÀ»½Ã)
Çϱâ À§ÇØ ÇÊ¿äÇÑ Å©±âÀÇ 2¹è¸¸Å­ÀÌ´Ù.

Áï 2¹è¾¿ Áõ°¡ÇÑ´Ù´Â °ÍÀÌ´Ù. ÀÌ °æ¿ì³×´Â ¹öÆÛÀÇ ³»¿ëÀ» Á» ´õÅ« ¹öÆÛÃøÀ¸·Î º¹»çÇÏ´Â
ÀÏÀ» ¹Ýµå½Ã ÇØ¾ß ÇÑ´Ù.

°á±¹ ¿©±â¼­ StringBufferÀÇ Å©±â¸¦ ¿¹»óÇÏ¿© È¿°úÀûÀ¸·Î Àû¿ë½ÃÄÑÁشٸé, 
list¸¦ stringÇüÅ·Πº¯È¯Çϴµ¥ À־ Standard API¸¦ ÀÌ¿ëÇÒ °æ¿ì ÃÖ¼Ò 3¹èÀÌ»ó, 
local cache¸¦ ÀÌ¿ëÇÒ °æ¿ì ÃÖ¼Ò 2¹èÀÌ»óÀÇ ¼º´ÉÀ» º¸ÀåÇÒ¼ö ÀÖ°Ô µÈ´Ù.

»ùÇÃÄڵ带 º¸µµ·Ï ÇÏÀÚ.

    public class GrowDemo {
        static final int N = 1000000;
        static final String str = "testing";
    
        public static void main(String args[]) {
            StringBuffer sb = new StringBuffer();
            file://StringBuffer sb = new StringBuffer(N * str.length());
    
            long start = System.currentTimeMillis();
            for (int i = 1; i <= N; i++) {
                sb.append(str);
            }
            long elapsed = System.currentTimeMillis() - start;
            System.out.println(elapsed);
        }
    }

À§ÀÇ ¿¹Á¦´Â N°³ÀÇ ½ºÆ®¸µÀ» ¹öÆ۾ȿ¡ Ãß°¡½ÃÅ°´Â °ÍÀ» 100¸¸¹øÀÇ ·çÇÁ·Î Å×½ºÆ®ÇÏ¿´´Ù.
¿©±â¼­´Â °¢°¢ÀÇ ½ºÆ®¸µ¿¡ ´ëÇÑ ±æÀ̸¦ ¾Ë°í Àֱ⶧¹®¿¡ ¹öÆÛÀÇ ÃÖÀûÈ­µÇ¾îÁø Å©±â¸¦
°è»êÇÏ¿© ÃʱâÈ­½Ãų¼ö ÀÖÀ»°ÍÀ̸ç, ÀÌ °æ¿ì´Â ¹öÆÛ°¡ ÇÑ°è°ªÀ» ÃÊ°úÇÏ¿© º¹»ç¿Í 
ÀçÇÒ´çµÇ¾îÁö´Â ÀÏÀ» ¹Ì¿¬¿¡ ¹æÁöÇÒ¼ö ÀÖÀ»°ÍÀÌ´Ù.

À§ÀÇ ÇÁ·Î±×·¥ÀÇ °á°ú°ªÀ» ¾Æ·¡¿Í °°ÀÌ ³ª¿Ã°ÍÀÌ´Ù.

Å×½ºÆ® 

 Intel P-III 500, RAM 256, OS : Windows 2000 pro

1> »çÀÌÁ Á¤ÇÏÁö ¾ÊÀº °æ¿ì

1521 milli second

2> »çÀÌÁ Á¤ÇÑÈÄ Å×½ºÆ®

531 milli second

À§ÀÇ ±â·ÏÀ» º¸´õ¶óµµ ÃÖ¼ÒÇÑ 2¹èÀÇ ¼º´ÉÂ÷À̸¦ º¸ÀÌ´Â °ÍÀ» ¾Ë¼ö ÀÖ´Ù.

 

Article report :


 

ÀÌ·¯ÇÑ ±â¼úÀ» "downside"¶ó ºÎ¸¥´Ù. ¸¸¾à ÇÁ·Î±×·¥ ÀÛ¼º½Ã ¹öÆÛÀÇ Å©±â°¡ ¾ó¸¶³ª 
Ä¿¾ßµÉÁö¸¦ ¸ð¸¥´Ù¸é ¿¹»óÄ¡ ¹öÆÛÀÇ Å©±âº¸´Ù Á¶±Ý ´õ Å« »çÀÌÁ ÇÒ´çÇØ ÁÖ´Â °ÍÀÌ ÁÁ´Ù. 
¾îÂ÷¸® ³ªÁß¿¡ ¹ö·ÁÁö°Ô µÉ ¸Þ¸ð¸® ¿µ¿ªÀ̱⠶§¹®ÀÌ´Ù.
Å« ¹öÆÛÅ©±â¸¦ ´Ù·ç´Â °Íµµ ¾ÆÁÖ Áß¿äÇÑ ÀÏÀÌ µÉ¼ö ÀÖ´Ù´Â °ÍÀ» ¾Ë¾Æ¾ß ÇÑ´Ù.

ÀÌ·¯ÇÑ °°Àº ±â¼ú»óȲÇÏ¿¡¼­µµ ¼­·Î ´Ù¸¥ »óȲÀ» °í·ÁÇغ¼¼öµµ ÀÖ´Ù.
µ¥ÀÌÅͱ¸Á¶¿¡¼­ÀÇ ÃÖÁ¾ Å©±â¸¦ ÇÁ·Î±×·¡¸Ó°¡ Á÷Á¢ ¾Ë°í ÀÖ´Ù¸é ¾Æ¿¹ ±× Å©±â¸¦ Ŭ·¡½ºÀÇ 
»ý¼ºÀÚ¿¡¼­ ¸í½ÃÇØÁÖ´Â °Íµµ »ý°¢ÇØ º¼¼ö ÀÖ´Â °ÍÀÌ´Ù.

 
Written date 2001-05-20
 
1
References
 
Copyright ¨Ï 2003 www.javapattern.info & www.jlook.com, an jLOOK co.,LTD