Last active
July 1, 2020 14:33
-
-
Save Eyre-S/af3a42f1d272c5e33ec8bf52e191571c to your computer and use it in GitHub Desktop.
UtilsTest
This file contains 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 cc.sukazyo.test; | |
import java.util.Date; | |
public class RegexSpeedTest { | |
public static void main(String[] args) throws InterruptedException { | |
int countsTotal = 0; | |
long timeTotal = 0; | |
for (int i = 1; i <= 20; i++) { | |
RegexTest reg = new RegexTest(); | |
System.out.println("===================="); | |
System.out.println("Start Regex Test Numbered " + i); | |
System.out.println("===================="); | |
reg.start(); | |
Thread.sleep(3000); | |
reg.interrupt(); | |
while (reg.running) {} | |
Thread.sleep(10); | |
System.out.println("Test Complete!"); | |
System.out.println("Now String: " + reg.now); | |
System.out.println("Total Count: " + reg.count + " times"); | |
countsTotal += reg.count; | |
System.out.println("Time Used: " + (reg.stopTime - reg.startTime) + " ms"); | |
timeTotal += reg.stopTime - reg.startTime; | |
} | |
System.out.println("===================="); | |
System.out.println("===================="); | |
System.out.println("Average " + countsTotal/(timeTotal/1000) + " times/s"); | |
System.out.println("Average " + countsTotal/timeTotal + " times/ms"); | |
} | |
static class RegexTest extends Thread { | |
boolean running = false; | |
String now; | |
int count; | |
long startTime; | |
long stopTime; | |
@Override | |
public void run() { | |
running = true; | |
startTime = new Date().getTime(); | |
System.out.println("Thread Start!!! at " + startTime); | |
while (!isInterrupted()) { | |
now = "dnaineiopnpianepw{{HIESD}}o wndopnapo ndpa nwdonao[w sm;m ad".replaceAll("\\{\\{HIESD}}", "wahe0io"); | |
count++; | |
} | |
stopTime = new Date().getTime(); | |
running = false; | |
System.out.println("Thread Done!!! at " + stopTime); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment