apache/commons-lang — pull request #27 by librucha (2014-06-20 09:51:56+00:00)
Title: Reimplemented normalize space

Hi.
I reimplemented normalize space method of String utils, because regexp is much more rich operation than array traversing and I use this normalization often.
Here is benchmark created using google caliper.

0% Scenario{vm=java, trial=0, benchmark=ApacheNormalize, length=0} 1553.39 ns; σ=142.64 ns @ 10 trials
13% Scenario{vm=java, trial=0, benchmark=NewNormalize, length=0} 114.80 ns; σ=1.00 ns @ 3 trials
25% Scenario{vm=java, trial=0, benchmark=ApacheNormalize, length=10} 1513.44 ns; σ=133.58 ns @ 10 trials
38% Scenario{vm=java, trial=0, benchmark=NewNormalize, length=10} 114.49 ns; σ=1.05 ns @ 3 trials
50% Scenario{vm=java, trial=0, benchmark=ApacheNormalize, length=100} 1545.23 ns; σ=107.97 ns @ 10 trials
63% Scenario{vm=java, trial=0, benchmark=NewNormalize, length=100} 114.28 ns; σ=0.65 ns @ 3 trials
75% Scenario{vm=java, trial=0, benchmark=ApacheNormalize, length=1000} 1550.35 ns; σ=138.57 ns @ 10 trials
88% Scenario{vm=java, trial=0, benchmark=NewNormalize, length=1000} 115.16 ns; σ=1.14 ns @ 3 trials

benchmark length ns linear runtime
ApacheNormalize 0 1553 ==============================
ApacheNormalize 10 1513 =============================
ApacheNormalize 100 1545 =============================
ApacheNormalize 1000 1550 =============================
NewNormalize 0 115 ==
NewNormalize 10 114 ==
NewNormalize 100 114 ==
NewNormalize 1000 115 ==

vm: java
trial: 0