⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 messageformatterperftest.java

📁 Java开发最新的日志记录工具slf4j的源码
💻 JAVA
字号:
package org.slf4j.helpers;

import java.text.MessageFormat;

import junit.framework.TestCase;

public class MessageFormatterPerfTest extends TestCase {

  Integer i1 = new Integer(1);
  static long RUN_LENGTH = 100000;
  static long REFERENCE_BIPS = 9000;
  
  public MessageFormatterPerfTest(String name) {
    super(name);
  }

  protected void setUp() throws Exception {
  }

  protected void tearDown() throws Exception {
  }

  public void XtestJDKFormatterPerf() {
    jdkMessageFormatter(RUN_LENGTH);
    double duration = jdkMessageFormatter(RUN_LENGTH);
    System.out.println("jdk duration = "+duration+" nanos");
  }
  
  public void testSLF4JPerf() {
    slf4jMessageFormatter(RUN_LENGTH);
    double duration = slf4jMessageFormatter(RUN_LENGTH);
    long referencePerf = 140;
    BogoPerf.assertDuration(duration, referencePerf, REFERENCE_BIPS);
  }

  public double slf4jMessageFormatter(long len) {
    String s = ""; 
    s += ""; // keep compiler happy
    long start = System.currentTimeMillis();
    for (int i = 0; i < len; i++) {
      s = MessageFormatter.format("This is some rather short message {} ", i1);
    }
    long end = System.currentTimeMillis();
    return (1.0*end - start);
  }  
  public double jdkMessageFormatter(long len) {
    String s = ""; 
    s += ""; // keep compiler happy
    long start = System.currentTimeMillis();
    Object[] oa = new Object[] {i1};
    for (int i = 0; i < len; i++) {
      s = MessageFormat.format("This is some rather short message {0}", oa);
    }
    long end = System.currentTimeMillis();
    return (1.0*end - start);
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -