chukwa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Xiaoming Shi (JIRA)" <j...@apache.org>
Subject [jira] Commented: (CHUKWA-584) Multiple replace function call can be replaced with a single for loop to improve performance
Date Sun, 13 Mar 2011 04:25:59 GMT

    [ https://issues.apache.org/jira/browse/CHUKWA-584?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13006141#comment-13006141
] 

Xiaoming Shi commented on CHUKWA-584:
-------------------------------------

Well, it depends on the frequency the functions are called and the length of the input.  It
can make a big difference if it's frequently used or the size of the input is large 

> Multiple replace function call can be replaced with a single for loop to improve performance

> ---------------------------------------------------------------------------------------------
>
>                 Key: CHUKWA-584
>                 URL: https://issues.apache.org/jira/browse/CHUKWA-584
>             Project: Chukwa
>          Issue Type: Bug
>          Components: data collection
>    Affects Versions: 0.4.0
>            Reporter: Xiaoming Shi
>
> {noformat}
> ./chukwa-0.4.0/src/java/org/apache/hadoop/chukwa/datacollection/writer/SeqFileWriter.java
 line: 179
> ./chukwa-0.4.0/src/java/org/apache/hadoop/chukwa/datacollection/writer/localfs/LocalWriter.java
  line:285
> {noformat}
> 3 consecutive replace() is called to remove the special characters.  It's 3+ times slower
than using a for loop 
> replace them all.
> {noformat}
> e.g.
>  - str.replace('a', '#');
>  - str.replace('b', '%');
>  + StringBuilder sb = new StringBuilder( str.length() );
>  + for (int i=0; i < str.length(); i++)
>  +  {
>  +           char c = str.charAt(i);
>  +         if ( c == 'a' )
>  +               sb.append('#');
>  +       else if ( c== 'b' )
>  +               sb.append('%');
>  +       else 
>  +              sb.append(c); 
>  +  }
>  +  str  = sb.toString();
> {noformat}
> This bug has the same problem as the MySQL bug : http://bugs.mysql.com/bug.php?id=45699

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message