This specific content was written 13 years ago.
Please keep this in mind as it may be outdated and not adhering to best-practices.
I wanted to write my own character escaper for requests going to Apache Lucent.
After writing my own, I also received feedback from programmers-stackexchange which resulted in the fastest implementation, also posted here. (Thanks to MrSmit42)
Below is my application that tests 6 different slightly different implementations over 30,000,000 executions each and outputs the time in MS.
The results in MS (on my computer) were the following:
Method 1 (Boolean Array)-> 7574
Method 0 (Switch Stmt)-> 9778
Method 4 (Switch Stmt Ugly – BreakPoints after evert case)-> 12451
Method 6 (HashSet)-> 17273
Method 5 (EnumMap)-> 39516
Method 3 (Pattern/Regex)-> 98229
This proves that for production systems that have many requests, jumping directly on the RegEx bandwagon for even trivial problems is not always the solution.
Even a 0,5 MS reduction per request leads to 50MS saved over 100 requests (per second) and 500MS over 1000 requests.
[polldaddy poll=7418939]
Sep 23 2013
Optimized Character Escaper for Java
I wanted to write my own character escaper for requests going to Apache Lucent.
After writing my own, I also received feedback from programmers-stackexchange which resulted in the fastest implementation, also posted here. (Thanks to MrSmit42)
Below is my application that tests 6 different slightly different implementations over 30,000,000 executions each and outputs the time in MS.
The results in MS (on my computer) were the following:
Method 1 (Boolean Array)-> 7574
Method 0 (Switch Stmt)-> 9778
Method 4 (Switch Stmt Ugly – BreakPoints after evert case)-> 12451
Method 6 (HashSet)-> 17273
Method 5 (EnumMap)-> 39516
Method 3 (Pattern/Regex)-> 98229
This proves that for production systems that have many requests, jumping directly on the RegEx bandwagon for even trivial problems is not always the solution.
Even a 0,5 MS reduction per request leads to 50MS saved over 100 requests (per second) and 500MS over 1000 requests.
[polldaddy poll=7418939]
By Menelaos Bakopoulos • Java SE, Programming, Scripts 0 • Tags: Escape Characters, Java SE