CryptoMorin

Java - Pass String By Reference

Nov 22nd, 2020
397
168 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @Fork(jvmArgs = {"-Xmx8G", "-Xms4G"})
  2. @OutputTimeUnit(TimeUnit.MILLISECONDS)
  3. @State(Scope.Benchmark)
  4. @BenchmarkMode(Mode.Throughput)
  5. @Warmup(iterations = 5)
  6. @Measurement(iterations = 5)
  7. public class Main {
  8.     private static final String SUBJECT = RandomStringUtils.randomAlphabetic(10000);
  9.     private static final MutableString MUTABLE_SUBJECT = new MutableString(SUBJECT);
  10.  
  11.     public static void main(String[] args) throws IOException, RunnerException {
  12.         System.out.println("Subject: " + SUBJECT);
  13.         org.openjdk.jmh.Main.main(args);
  14.     }
  15.  
  16.     @Benchmark
  17.     public static void mutableString() {
  18.         computeMutable(MUTABLE_SUBJECT);
  19.     }
  20.  
  21.     @Benchmark
  22.     public static void immutableString() {
  23.         computeImmutable(SUBJECT);
  24.     }
  25.  
  26.     private static void computeImmutable(String str) {
  27.     }
  28.  
  29.     private static void computeMutable(MutableString str) {
  30.     }
  31. }
RAW Paste Data