You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Felix Meschberger <fm...@adobe.com> on 2014/03/14 11:51:59 UTC

ResourceUtil.resourceTypeToPath: String.replaceAll

Hi

I am playing around with performance testing and noticed that the ResourceUtil.resourceTypeToPath method uses String.replaceAll to replace colons with slashes.

I have the impression using a regular expression to replace a single character with another character is overkill and replacing this code with a simple "String.replace(':', '/')" might be more appropriate.

WDYT ?

Regards
Felix

Re: ResourceUtil.resourceTypeToPath: String.replaceAll

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Fri, Mar 14, 2014 at 1:17 PM, Felix Meschberger <fm...@adobe.com> wrote:
> ..just for the fun of it created a stupid microbenchmark indicating the
> char String.replace(char, char) based implementation to be almost 6x
> times faster than the old one ;-)...

Way to go! Thanks for tackling this.

-Bertrand

Re: ResourceUtil.resourceTypeToPath: String.replaceAll

Posted by Felix Meschberger <fm...@adobe.com>.
Hi

Am 14.03.2014 um 11:56 schrieb Bertrand Delacretaz <bd...@apache.org>:

> Hi,
> 
> On Fri, Mar 14, 2014 at 11:51 AM, Felix Meschberger <fm...@adobe.com> wrote:
>> ...I have the impression using a regular expression to replace a single
>> character with another character is overkill and replacing this code
>> with a simple "String.replace(':', '/')" might be more appropriate....
> 
> If that's covered by tests, and those tests handle the case where
> there are several colons in a resource type (which is legal, right?)

Right. I created the test and the method works, indeed (as documented by String.replace() ;-) )

> and your measurements show significantly better performance, why not
> ;-)

Hehe, just for the fun of it created a stupid microbenchmark indicating the char String.replace(char, char) based implementation to be almost 6x times faster than the old one ;-)

Regards
Felix


Re: ResourceUtil.resourceTypeToPath: String.replaceAll

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi,

On Fri, Mar 14, 2014 at 11:51 AM, Felix Meschberger <fm...@adobe.com> wrote:
> ...I have the impression using a regular expression to replace a single
> character with another character is overkill and replacing this code
> with a simple "String.replace(':', '/')" might be more appropriate....

If that's covered by tests, and those tests handle the case where
there are several colons in a resource type (which is legal, right?)
and your measurements show significantly better performance, why not
;-)

-Bertrand

Re: ResourceUtil.resourceTypeToPath: String.replaceAll

Posted by Carsten Ziegeler <cz...@apache.org>.
+1


2014-03-14 11:51 GMT+01:00 Felix Meschberger <fm...@adobe.com>:

> Hi
>
> I am playing around with performance testing and noticed that the
> ResourceUtil.resourceTypeToPath method uses String.replaceAll to replace
> colons with slashes.
>
> I have the impression using a regular expression to replace a single
> character with another character is overkill and replacing this code with a
> simple "String.replace(':', '/')" might be more appropriate.
>
> WDYT ?
>
> Regards
> Felix




-- 
Carsten Ziegeler
cziegeler@apache.org