changeset 100:b71b3f7d24d4

Primitive performance test
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 28 Jan 2011 02:15:12 +0100
parents 4d7bb95d553b
children 777ab7034c1b
files test/org/tmatesoft/hg/test/TestHistory.java test/org/tmatesoft/hg/test/TestStatus.java
diffstat 2 files changed, 42 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/test/org/tmatesoft/hg/test/TestHistory.java	Thu Jan 27 23:08:51 2011 +0100
+++ b/test/org/tmatesoft/hg/test/TestHistory.java	Fri Jan 28 02:15:12 2011 +0100
@@ -22,12 +22,14 @@
 
 import org.tmatesoft.hg.core.Cset;
 import org.tmatesoft.hg.core.LogCommand;
+import org.tmatesoft.hg.core.StatusCommand;
 import org.tmatesoft.hg.core.LogCommand.CollectHandler;
 import org.tmatesoft.hg.core.LogCommand.FileHistoryHandler;
 import org.tmatesoft.hg.core.LogCommand.FileRevision;
 import org.tmatesoft.hg.core.Path;
 import org.tmatesoft.hg.repo.HgRepository;
 import org.tmatesoft.hg.repo.HgLookup;
+import org.tmatesoft.hg.repo.HgStatusCollector;
 import org.tmatesoft.hg.test.LogOutputParser.Record;
 
 
@@ -46,6 +48,7 @@
 		TestHistory th = new TestHistory(new HgLookup().detectFromWorkingDir());
 		th.testCompleteLog();
 		th.testFollowHistory();
+		th.testPerformance();
 	}
 
 	public TestHistory(HgRepository hgRepo) {
@@ -112,4 +115,19 @@
 		}
 		System.out.println(what + (hasErrors ? " FAIL" : " OK"));
 	}
+
+	public void testPerformance() throws Exception {
+		final int runs = 10;
+		final long start1 = System.currentTimeMillis();
+		for (int i = 0; i < runs; i++) {
+			changelogParser.reset();
+			eh.run("hg", "log", "--debug");
+		}
+		final long start2 = System.currentTimeMillis();
+		for (int i = 0; i < runs; i++) {
+			new LogCommand(repo).execute();
+		}
+		final long end = System.currentTimeMillis();
+		System.out.printf("'hg log --debug', %d runs: Native client total %d (%d per run), Java client %d (%d)\n", runs, start2-start1, (start2-start1)/runs, end-start2, (end-start2)/runs);
+	}
 }
--- a/test/org/tmatesoft/hg/test/TestStatus.java	Thu Jan 27 23:08:51 2011 +0100
+++ b/test/org/tmatesoft/hg/test/TestStatus.java	Fri Jan 28 02:15:12 2011 +0100
@@ -47,6 +47,7 @@
 		TestStatus test = new TestStatus(repo);
 		test.testLowLevel();
 		test.testStatusCommand();
+		test.testPerformance();
 	}
 	
 	public TestStatus(HgRepository hgRepo) {
@@ -112,6 +113,29 @@
 		 */
 	}
 	
+	/*
+	 * With warm-up of previous tests, 10 runs, time in milliseconds
+	 * 'hg status -A': Native client total 953 (95 per run), Java client 94 (9)
+	 * 'hg status -A --rev 3:80': Native client total 1828 (182 per run), Java client 235 (23)
+	 * 'hg log --debug', 10 runs: Native client total 1766 (176 per run), Java client 78 (7)
+	 */
+	public void testPerformance() throws Exception {
+		final int runs = 10;
+		final long start1 = System.currentTimeMillis();
+		for (int i = 0; i < runs; i++) {
+			statusParser.reset();
+			eh.run("hg", "status", "-A", "--rev", "3:80");
+		}
+		final long start2 = System.currentTimeMillis();
+		for (int i = 0; i < runs; i++) {
+			HgStatusCollector.Record r = new HgStatusCollector.Record();
+			new StatusCommand(repo).all().base(3).revision(80).execute(r);
+		}
+		final long end = System.currentTimeMillis();
+		System.out.printf("'hg status -A --rev 3:80', %d runs:  Native client total %d (%d per run), Java client %d (%d)\n", runs, start2-start1, (start2-start1)/runs, end-start2, (end-start2)/runs);
+	}
+	
+	
 	private static void report(String what, HgStatusCollector.Record r, StatusOutputParser statusParser) {
 		System.out.println(">>>" + what);
 		reportNotEqual("MODIFIED", r.getModified(), statusParser.getModified());