We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import org.springframework.util.StopWatch; import java.util.Arrays; import java.util.function.BooleanSupplier; public class LambdaMain { public static void main(String[] args) { var arr = new String[100_000]; for (int i = 0; i < arr.length; i++) { arr[i] = "" + Math.random(); } var sw = new StopWatch(); sw.start(); var result = ""; for (int i = 0; i < arr.length; i++) { result += arr[i]; } sw.stop(); System.out.println(">>> String +: " + sw.getLastTaskTimeMillis() + "ms"); sw.start(); var buffer = new StringBuffer(); for (int i = 0; i < arr.length; i++) { buffer.append(arr[i]); } result = buffer.toString(); sw.stop(); System.out.println(">>> StringBuffer without capacity: " + sw.getLastTaskTimeMillis() + "ms"); sw.start(); result = String.join("", arr); sw.stop(); System.out.println(">>> String.join: " + sw.getLastTaskTimeMillis() + "ms"); sw.start(); var builder = new StringBuilder(); for (int i = 0; i < arr.length; i++) { builder.append(arr[i]); } result = builder.toString(); sw.stop(); System.out.println(">>> StringBuilder without capacity: " + sw.getLastTaskTimeMillis() + "ms"); sw.start(); builder = new StringBuilder(1_000_000); for (int i = 0; i < arr.length; i++) { builder.append(arr[i]); } result = builder.toString(); sw.stop(); System.out.println(">>> StringBuilder with capacity: " + sw.getLastTaskTimeMillis() + "ms"); sw.start(); buffer = new StringBuffer(1_000_000); for (int i = 0; i < arr.length; i++) { buffer.append(arr[i]); } result = buffer.toString(); sw.stop(); System.out.println(">>> StringBuffer with capacity: " + sw.getLastTaskTimeMillis() + "ms"); sw.start(); result = String.join("", arr); sw.stop(); System.out.println(">>> String.join: " + sw.getLastTaskTimeMillis() + "ms"); sw.start(); result = ""; for (int i = 0; i < arr.length; i++) { result += arr[i]; } sw.stop(); System.out.println(">>> String +: " + sw.getLastTaskTimeMillis() + "ms"); } }
(핫스팟 영향이 있음)
String +: 10173ms StringBuffer without capacity: 9ms String.join: 13ms StringBuilder without capacity: 2ms StringBuilder with capacity: 2ms StringBuffer with capacity: 3ms String.join: 4ms
The text was updated successfully, but these errors were encountered:
No branches or pull requests
소스
결과
(핫스팟 영향이 있음)
The text was updated successfully, but these errors were encountered: