Created
August 10, 2012 20:04
-
-
Save danlangford/3317428 to your computer and use it in GitHub Desktop.
native vs stringutils
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package dan.langford; | |
import static org.testng.Assert.assertEquals; | |
import java.util.logging.Logger; | |
import org.apache.commons.lang.StringUtils; | |
import org.springframework.util.StopWatch; | |
import org.testng.annotations.Test; | |
public class ATest { | |
private static Logger LOG = Logger.getAnonymousLogger(); | |
@Test | |
public void f() { | |
String input = "8789_25Langford_5_te.xml", actual = null, expected="8789_25Langford"; | |
// avoid logging,asserting inside active stopwatch | |
StopWatch sw1 = new StopWatch(), sw2=new StopWatch(); | |
for (int i = 0; i++ < 10;) { | |
sw1.start("java native api+"+1); | |
for (int j = 0; j++ < 5000000;) { | |
actual = input.substring(0, input.indexOf('_', input.indexOf('_')+1)); | |
} | |
sw1.stop(); | |
assertEquals(actual, expected); | |
sw2.start("apache commons stringutils+"+i); | |
for (int k = 0; k++ < 5000000;) { | |
actual = StringUtils.substring(input, 0,StringUtils.indexOf(input, '_',StringUtils.indexOf(input, '_')+1)); | |
} | |
sw2.stop(); | |
assertEquals(actual, expected); | |
} | |
LOG.info("java native api avg "+ (sw1.getTotalTimeMillis() / sw1.getTaskCount()) ); | |
LOG.info("apache commons stringutils avg "+ (sw2.getTotalTimeMillis() / sw2.getTaskCount()) ); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Suites: 0 and:0 | |
[TestNG] Running: | |
C:\Users\danlangford.LDS\AppData\Local\Temp\testng-eclipse--2021784807\testng-customsuite.xml | |
Aug 10, 2012 3:09:01 PM dan.langford.ATest f | |
INFO: sw1 avg 182 | |
Aug 10, 2012 3:09:01 PM dan.langford.ATest f | |
INFO: sw2 avg 198 | |
PASSED: f | |
=============================================== | |
Default test | |
Tests run: 1, Failures: 0, Skips: 0 | |
=============================================== | |
=============================================== | |
Default suite | |
Total tests run: 1, Failures: 0, Skips: 0 | |
=============================================== | |
[TestNG] Time taken by [TestListenerAdapter] Passed:0 Failed:0 Skipped:0]: 0 ms | |
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@1342a80d: 8 ms | |
[TestNG] Time taken by org.testng.reporters.XMLReporter@29e97f9f: 13 ms | |
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@25595f51: 28 ms | |
[TestNG] Time taken by org.testng.reporters.EmailableReporter@6cb8: 4 ms | |
[TestNG] Time taken by org.testng.reporters.jq.Main@53ebd75b: 48 ms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment