當前位置: 首頁>>代碼示例>>Java>>正文


Java Stats類代碼示例

本文整理匯總了Java中com.google.javascript.jscomp.PerformanceTracker.Stats的典型用法代碼示例。如果您正苦於以下問題:Java Stats類的具體用法?Java Stats怎麽用?Java Stats使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Stats類屬於com.google.javascript.jscomp.PerformanceTracker包,在下文中一共展示了Stats類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testStatsCalculation

import com.google.javascript.jscomp.PerformanceTracker.Stats; //導入依賴的package包/類
public void testStatsCalculation() {
  PerformanceTracker tracker =
      new PerformanceTracker(emptyExternRoot, emptyJsRoot, TracerMode.ALL, null);
  CodeChangeHandler handler = tracker.getCodeChangeHandler();

  // It's sufficient for this test to assume that a single run of any pass
  // takes some fixed amount of time, say 5ms.
  int passRuntime = 5;

  tracker.recordPassStart("noloopA", true);
  handler.reportChange();
  tracker.recordPassStop("noloopA", passRuntime);

  tracker.recordPassStart("noloopB", true);
  handler.reportChange();
  tracker.recordPassStop("noloopB", passRuntime);

  tracker.recordPassStart("loopA", false);
  handler.reportChange();
  tracker.recordPassStop("loopA", passRuntime);

  tracker.recordPassStart("loopA", false);
  tracker.recordPassStop("loopA", passRuntime);

  tracker.recordPassStart("noloopB", true);
  handler.reportChange();
  tracker.recordPassStop("noloopB", passRuntime);

  tracker.recordPassStart("loopB", false);
  tracker.recordPassStop("loopB", passRuntime);

  tracker.recordPassStart("noloopB", true);
  tracker.recordPassStop("noloopB", passRuntime);

  int numRuns = tracker.getRuns();

  assertEquals(7, numRuns);
  assertEquals(tracker.getRuntime(), numRuns * passRuntime);
  assertEquals(3, tracker.getLoopRuns());
  assertEquals(4, tracker.getChanges()); /* reportChange was called 4 times */
  assertEquals(1, tracker.getLoopChanges());

  ImmutableMap<String, Stats> stats = tracker.getStats();
  Stats st = stats.get("noloopA");
  assertEquals(1, st.runs);
  assertEquals(st.runtime, passRuntime);
  assertEquals(1, st.changes);

  st = stats.get("noloopB");
  assertEquals(3, st.runs);
  assertEquals(st.runtime, 3 * passRuntime);
  assertEquals(2, st.changes);

  st = stats.get("loopA");
  assertEquals(2, st.runs);
  assertEquals(st.runtime, 2 * passRuntime);
  assertEquals(1, st.changes);

  st = stats.get("loopB");
  assertEquals(1, st.runs);
  assertEquals(st.runtime, passRuntime);
  assertEquals(0, st.changes);
}
 
開發者ID:google,項目名稱:closure-compiler,代碼行數:64,代碼來源:PerformanceTrackerTest.java

示例2: testStatsCalculation

import com.google.javascript.jscomp.PerformanceTracker.Stats; //導入依賴的package包/類
public void testStatsCalculation() {
  PerformanceTracker tracker =
      new PerformanceTracker(emptyScript, TracerMode.ALL);
  CodeChangeHandler handler = tracker.getCodeChangeHandler();

  // It's sufficient for this test to assume that a single run of any pass
  // takes some fixed amount of time, say 5ms.
  int passRuntime = 5;

  tracker.recordPassStart("noloopA", true);
  handler.reportChange();
  tracker.recordPassStop("noloopA", passRuntime);

  tracker.recordPassStart("noloopB", true);
  handler.reportChange();
  tracker.recordPassStop("noloopB", passRuntime);

  tracker.recordPassStart("loopA", false);
  handler.reportChange();
  tracker.recordPassStop("loopA", passRuntime);

  tracker.recordPassStart("loopA", false);
  tracker.recordPassStop("loopA", passRuntime);

  tracker.recordPassStart("noloopB", true);
  handler.reportChange();
  tracker.recordPassStop("noloopB", passRuntime);

  tracker.recordPassStart("loopB", false);
  tracker.recordPassStop("loopB", passRuntime);

  tracker.recordPassStart("noloopB", true);
  tracker.recordPassStop("noloopB", passRuntime);

  int numRuns = tracker.getRuns();

  assertEquals(numRuns, 7);
  assertEquals(tracker.getRuntime(), numRuns * passRuntime);
  assertEquals(tracker.getLoopRuns(), 3);
  assertEquals(tracker.getChanges(), 4); /* reportChange was called 4 times */
  assertEquals(tracker.getLoopChanges(), 1);

  ImmutableMap<String, Stats> stats = tracker.getStats();
  Stats st = stats.get("noloopA");
  assertEquals(st.runs, 1);
  assertEquals(st.runtime, passRuntime);
  assertEquals(st.changes, 1);

  st = stats.get("noloopB");
  assertEquals(st.runs, 3);
  assertEquals(st.runtime, 3 * passRuntime);
  assertEquals(st.changes, 2);

  st = stats.get("loopA");
  assertEquals(st.runs, 2);
  assertEquals(st.runtime, 2 * passRuntime);
  assertEquals(st.changes, 1);

  st = stats.get("loopB");
  assertEquals(st.runs, 1);
  assertEquals(st.runtime, passRuntime);
  assertEquals(st.changes, 0);
}
 
開發者ID:nicks,項目名稱:closure-compiler-old,代碼行數:64,代碼來源:PerformanceTrackerTest.java


注:本文中的com.google.javascript.jscomp.PerformanceTracker.Stats類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。