comparison test/org/tmatesoft/hg/test/MapTagsToFileRevisions.java @ 329:694ebabb5cb3

Refactor revlog patch mechanism, towards patch merging
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 13 Oct 2011 03:30:50 +0200
parents d42a45a2c9d6
children 5f9073eabf06
comparison
equal deleted inserted replaced
328:a674b8590362 329:694ebabb5cb3
38 // Static ================================================================= 38 // Static =================================================================
39 39
40 public static void main(String[] args) throws Exception { 40 public static void main(String[] args) throws Exception {
41 MapTagsToFileRevisions m = new MapTagsToFileRevisions(); 41 MapTagsToFileRevisions m = new MapTagsToFileRevisions();
42 System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory()); 42 System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory());
43 m.collectTagsPerFile(); 43 m.measurePatchAffectsArbitraryRevisionRead();
44 // m.collectTagsPerFile();
44 // m.manifestWalk(); 45 // m.manifestWalk();
45 // m.changelogWalk(); 46 // m.changelogWalk();
46 // m.revisionMap(); 47 // m.revisionMap();
47 // m.buildFile2ChangelogRevisionMap(); 48 // m.buildFile2ChangelogRevisionMap();
48 m = null; 49 m = null;
49 System.gc(); 50 System.gc();
50 System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory()); 51 System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory());
51 } 52 }
52 53
54
55 // revision == 2406 - 5 ms per run (baseRevision == 2406)
56 // revision == 2405 - 69 ms per run (baseRevision == 1403)
57 private void measurePatchAffectsArbitraryRevisionRead() throws Exception {
58 final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython"));
59 final DoNothingManifestInspector insp = new DoNothingManifestInspector();
60 final int revision = 2405;
61 // warm-up.
62 repository.getManifest().walk(revision, revision, insp);
63 final int runs = 10;
64 final long start = System.nanoTime();
65 for (int i = 0; i < runs; i++) {
66 repository.getManifest().walk(revision, revision, insp);
67 }
68 final long end = System.nanoTime();
69 System.out.printf("%d ms per run\n", (end - start)/ (runs*1000000));
70 }
71
53 /* 72 /*
54 * .hgtags, 261 revisions 73 * .hgtags, 261 revisions
55 * Approach 1: total 83, init: 0, iteration: 82 74 * Approach 1: total 83, init: 0, iteration: 82
56 * Approach 2: total 225, init: 206, iteration: 19 75 * Approach 2: total 225, init: 206, iteration: 19
57 * README, 465 revisions 76 * README, 465 revisions
172 191
173 private void manifestWalk() throws Exception { 192 private void manifestWalk() throws Exception {
174 System.out.println(System.getProperty("java.version")); 193 System.out.println(System.getProperty("java.version"));
175 final long start = System.currentTimeMillis(); 194 final long start = System.currentTimeMillis();
176 final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython")); 195 final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython"));
177 repository.getManifest().walk(0, 10000, new HgManifest.Inspector2() { 196 repository.getManifest().walk(0, 10000, new DoNothingManifestInspector());
178 public boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision) {
179 return true;
180 }
181 public boolean next(Nodeid nid, String fname, String flags) {
182 throw new HgBadStateException(HgManifest.Inspector2.class.getName());
183 }
184 public boolean next(Nodeid nid, Path fname, Flags flags) {
185 return true;
186 }
187 public boolean end(int manifestRevision) {
188 return true;
189 }
190 });
191 // cpython: 1,1 sec for 0..1000, 43 sec for 0..10000, 115 sec for 0..20000 (Pool with HashMap) 197 // cpython: 1,1 sec for 0..1000, 43 sec for 0..10000, 115 sec for 0..20000 (Pool with HashMap)
192 // 2,4 sec for 1000..2000 198 // 2,4 sec for 1000..2000
193 // cpython -r 1000: 484 files, -r 2000: 1015 files. Iteration 1000..2000; fnamePool.size:1019 nodeidPool.size:2989 199 // cpython -r 1000: 484 files, -r 2000: 1015 files. Iteration 1000..2000; fnamePool.size:1019 nodeidPool.size:2989
194 // nodeidPool for two subsequent revisions only: 840. 37 sec for 0..10000. 99 sec for 0..20k 200 // nodeidPool for two subsequent revisions only: 840. 37 sec for 0..10000. 99 sec for 0..20k
195 // 0..10000 fnamePool: hits:15989152, misses:3020 201 // 0..10000 fnamePool: hits:15989152, misses:3020
238 final HgChangelog.RevisionMap clogrmap = repository.getChangelog().new RevisionMap().init(); 244 final HgChangelog.RevisionMap clogrmap = repository.getChangelog().new RevisionMap().init();
239 // map to look up tag by changeset local number 245 // map to look up tag by changeset local number
240 final IntMap<List<TagInfo>> tagLocalRev2TagInfo = new IntMap<List<TagInfo>>(allTags.length); 246 final IntMap<List<TagInfo>> tagLocalRev2TagInfo = new IntMap<List<TagInfo>>(allTags.length);
241 System.out.printf("Collecting manifests for %d tags\n", allTags.length); 247 System.out.printf("Collecting manifests for %d tags\n", allTags.length);
242 final int[] tagLocalRevs = collectLocalTagRevisions(clogrmap, allTags, tagLocalRev2TagInfo); 248 final int[] tagLocalRevs = collectLocalTagRevisions(clogrmap, allTags, tagLocalRev2TagInfo);
243 System.out.printf("Prepared tag revisions to analyze: %d ms\n", System.currentTimeMillis() - start); 249 System.out.printf("Prepared %d tag revisions to analyze: %d ms\n", tagLocalRevs.length, System.currentTimeMillis() - start);
244 250
245 final Path targetPath = Path.create("README"); 251 final Path targetPath = Path.create("README");
246 // 252 //
247 collectTagsPerFile_Approach_1(clogrmap, tagLocalRevs, allTags, targetPath); 253 collectTagsPerFile_Approach_1(clogrmap, tagLocalRevs, allTags, targetPath);
248 System.out.printf("Total time: %d ms\n", System.currentTimeMillis() - start); 254 System.out.printf("Total time: %d ms\n", System.currentTimeMillis() - start);
363 }); 369 });
364 System.out.printf("Alternative total time: %d ms, of that init: %d ms\n", (System.nanoTime() - start2)/1000000, (start2a-start2)/1000000); 370 System.out.printf("Alternative total time: %d ms, of that init: %d ms\n", (System.nanoTime() - start2)/1000000, (start2a-start2)/1000000);
365 System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory()); 371 System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory());
366 } 372 }
367 373
374 static class DoNothingManifestInspector implements HgManifest.Inspector2 {
375 public boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision) {
376 return true;
377 }
378 public boolean next(Nodeid nid, String fname, String flags) {
379 throw new HgBadStateException(HgManifest.Inspector2.class.getName());
380 }
381 public boolean next(Nodeid nid, Path fname, Flags flags) {
382 return true;
383 }
384 public boolean end(int manifestRevision) {
385 return true;
386 }
387 }
388
368 public static void main2(String[] args) throws HgException, CancelledException { 389 public static void main2(String[] args) throws HgException, CancelledException {
369 final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython")); 390 final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython"));
370 final Path targetPath = Path.create("README"); 391 final Path targetPath = Path.create("README");
371 final HgTags tags = repository.getTags(); 392 final HgTags tags = repository.getTags();
372 final Map<String, HgTags.TagInfo> tagToInfo = tags.getTags(); 393 final Map<String, HgTags.TagInfo> tagToInfo = tags.getTags();