commons-lang icon indicating copy to clipboard operation
commons-lang copied to clipboard

[LANG-1587] refine StringUtils.strip

Open XenoAmess opened this issue 4 years ago • 3 comments

as title.

XenoAmess avatar Jun 29 '20 16:06 XenoAmess

Coverage Status

Coverage increased (+0.006%) to 94.963% when pulling 079df6c514e4963dabdf0c99a660198a9efd1450 on xenoamess-fork:refine_strip into e233ab6b1464601341cc77ac489e9358aa45fbed on apache:master.

coveralls avatar Jun 29 '20 18:06 coveralls

full performance test at https://pastebin.ubuntu.com/p/xpZVrHpDXG/ In short,

StringUtilsStripTest.test00New        avgt    5         2.308 ?       0.046  ns/op

StringUtilsStripTest.test00Old        avgt    5         2.307 ?       0.072  ns/op

StringUtilsStripTest.test01New        avgt    5         2.546 ?       0.075  ns/op

StringUtilsStripTest.test01Old        avgt    5         2.543 ?       0.105  ns/op

StringUtilsStripTest.test10New        avgt    5        28.352 ?       1.662  ns/op

StringUtilsStripTest.test10Old        avgt    5         6.593 ?       0.467  ns/op

StringUtilsStripTest.test11New        avgt    5        17.817 ?       1.338  ns/op

StringUtilsStripTest.test11Old        avgt    5        17.940 ?       1.311  ns/op

StringUtilsStripTest.test20New        avgt    5        29.318 ?       1.701  ns/op

StringUtilsStripTest.test20Old        avgt    5         6.280 ?       0.710  ns/op

StringUtilsStripTest.test21New        avgt    5        22.556 ?       3.598  ns/op

StringUtilsStripTest.test21Old        avgt    5        22.761 ?       3.757  ns/op

StringUtilsStripTest.test30New        avgt    5        36.088 ?       7.050  ns/op

StringUtilsStripTest.test30Old        avgt    5        43.252 ?       4.774  ns/op

StringUtilsStripTest.test31New        avgt    5        23.776 ?       0.927  ns/op

StringUtilsStripTest.test31Old        avgt    5        38.795 ?       2.763  ns/op

StringUtilsStripTest.test40New        avgt    5        16.315 ?       0.904  ns/op

StringUtilsStripTest.test40Old        avgt    5        10.407 ?       0.766  ns/op

StringUtilsStripTest.test41New        avgt    5        11.135 ?       0.513  ns/op

StringUtilsStripTest.test41Old        avgt    5        12.398 ?       1.291  ns/op

StringUtilsStripTest.test50New        avgt    5        21.440 ?       5.537  ns/op

StringUtilsStripTest.test50Old        avgt    5        15.255 ?       2.052  ns/op

StringUtilsStripTest.test51New        avgt    5        16.892 ?       3.979  ns/op

StringUtilsStripTest.test51Old        avgt    5        16.976 ?       3.205  ns/op

StringUtilsStripTest.test60New        avgt    5        17.609 ?       1.803  ns/op

StringUtilsStripTest.test60Old        avgt    5        34.192 ?       3.271  ns/op

StringUtilsStripTest.test61New        avgt    5        14.651 ?       1.143  ns/op

StringUtilsStripTest.test61Old        avgt    5        30.726 ?       7.021  ns/op

StringUtilsStripTest.testStrings0New  avgt    5  25788975.165 ?16074023.892  ns/op

StringUtilsStripTest.testStrings0Old  avgt    5  29418606.310 ? 7928783.178  ns/op

StringUtilsStripTest.testStrings1New  avgt    5  19118531.531 ?  429275.123  ns/op

StringUtilsStripTest.testStrings1Old  avgt    5  25585907.686 ? 2117790.922  ns/op

indicates:

  1. when [only one side of that String contains whitespace] && [stripChars!=null] , the new function is slower.
  2. in other situations the new function runs faster.
  3. the new function runs faster in average (of all String in length 3)

So I really have no idea if we should merge this pr.

XenoAmess avatar Jul 28 '20 15:07 XenoAmess

@garydgregory rebased. please find some time to review. thanks.

XenoAmess avatar Feb 21 '21 16:02 XenoAmess