Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/MapTagsToFileRevisions.java @ 263:31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 18 Aug 2011 18:06:44 +0200 |
parents | ea0c0de86d0e |
children | c5980f287cc4 |
comparison
equal
deleted
inserted
replaced
262:3dcd3dd90c77 | 263:31f67be94e71 |
---|---|
5 import java.util.Arrays; | 5 import java.util.Arrays; |
6 import java.util.HashMap; | 6 import java.util.HashMap; |
7 import java.util.LinkedList; | 7 import java.util.LinkedList; |
8 import java.util.List; | 8 import java.util.List; |
9 import java.util.Map; | 9 import java.util.Map; |
10 import java.util.regex.Pattern; | |
10 | 11 |
11 import org.tmatesoft.hg.core.HgChangeset; | 12 import org.tmatesoft.hg.core.HgChangeset; |
12 import org.tmatesoft.hg.core.HgChangesetHandler; | 13 import org.tmatesoft.hg.core.HgChangesetHandler; |
13 import org.tmatesoft.hg.core.HgException; | 14 import org.tmatesoft.hg.core.HgException; |
14 import org.tmatesoft.hg.core.HgLogCommand; | 15 import org.tmatesoft.hg.core.HgLogCommand; |
17 import org.tmatesoft.hg.repo.HgDataFile; | 18 import org.tmatesoft.hg.repo.HgDataFile; |
18 import org.tmatesoft.hg.repo.HgLookup; | 19 import org.tmatesoft.hg.repo.HgLookup; |
19 import org.tmatesoft.hg.repo.HgManifest; | 20 import org.tmatesoft.hg.repo.HgManifest; |
20 import org.tmatesoft.hg.repo.HgRepository; | 21 import org.tmatesoft.hg.repo.HgRepository; |
21 import org.tmatesoft.hg.repo.HgTags; | 22 import org.tmatesoft.hg.repo.HgTags; |
23 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; | |
22 import org.tmatesoft.hg.repo.HgTags.TagInfo; | 24 import org.tmatesoft.hg.repo.HgTags.TagInfo; |
23 import org.tmatesoft.hg.util.CancelledException; | 25 import org.tmatesoft.hg.util.CancelledException; |
24 import org.tmatesoft.hg.util.Path; | 26 import org.tmatesoft.hg.util.Path; |
25 | 27 |
26 /** | 28 /** |
31 // Static ================================================================= | 33 // Static ================================================================= |
32 | 34 |
33 public static void main(String[] args) throws Exception { | 35 public static void main(String[] args) throws Exception { |
34 MapTagsToFileRevisions m = new MapTagsToFileRevisions(); | 36 MapTagsToFileRevisions m = new MapTagsToFileRevisions(); |
35 System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory()); | 37 System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory()); |
36 m.main(); | 38 // Pattern p = Pattern.compile("^doc/[^/]*?\\.[0-9]\\.(x|ht)ml"); |
39 // System.out.println(p.matcher("doc/asd.2.xml").matches()); | |
40 // System.out.println(p.matcher("doc/zxc.6.html").matches()); | |
41 m.collectTagsPerFile(); | |
42 // m.manifestWalk(); | |
37 m = null; | 43 m = null; |
38 System.gc(); | 44 System.gc(); |
39 System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory()); | 45 System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory()); |
40 } | 46 } |
41 | 47 |
42 private void main() throws HgException, CancelledException { | 48 private void changelogWalk() throws Exception { |
49 final long start = System.currentTimeMillis(); | |
50 final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython")); | |
51 repository.getChangelog().all(new HgChangelog.Inspector() { | |
52 public int xx = 0; | |
53 | |
54 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) { | |
55 if (xx+revisionNumber < 0) { | |
56 System.out.println(xx); | |
57 System.out.println(revisionNumber); | |
58 } | |
59 xx += revisionNumber; | |
60 } | |
61 }); | |
62 // cpython: 17 seconds, mem 132,9 -> 129,0 -> 131,7 | |
63 // cpyhton: 13 seconds. Of that, cumulative Patch.apply takes 8.8 seconds, RevlogStream.Inspector.next - 1.8 | |
64 System.out.printf("Total time: %d ms\n", System.currentTimeMillis() - start); | |
65 System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory()); | |
66 } | |
67 | |
68 private void manifestWalk() throws Exception { | |
69 final long start = System.currentTimeMillis(); | |
70 final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython")); | |
71 repository.getManifest().walk(0, 10000, new HgManifest.Inspector() { | |
72 | |
73 public boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision) { | |
74 return true; | |
75 } | |
76 | |
77 public boolean next(Nodeid nid, String fname, String flags) { | |
78 return true; | |
79 } | |
80 | |
81 public boolean end(int manifestRevision) { | |
82 return true; | |
83 } | |
84 }); | |
85 // cpython: 1,1 sec for 0..1000, 43 sec for 0..10000, 115 sec for 0..20000 (Pool with HashMap) | |
86 // 2,4 sec for 1000..2000 | |
87 // cpython -r 1000: 484 files, -r 2000: 1015 files. Iteration 1000..2000; fnamePool.size:1019 nodeidPool.size:2989 | |
88 // nodeidPool for two subsequent revisions only: 840. 37 sec for 0..10000. 99 sec for 0..20k | |
89 // 0..10000 fnamePool: hits:15989152, misses:3020 | |
90 System.out.printf("Total time: %d ms\n", System.currentTimeMillis() - start); | |
91 System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory()); | |
92 } | |
93 | |
94 private void collectTagsPerFile() throws HgException, CancelledException { | |
43 final long start = System.currentTimeMillis(); | 95 final long start = System.currentTimeMillis(); |
44 final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython")); | 96 final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython")); |
45 final HgTags tags = repository.getTags(); | 97 final HgTags tags = repository.getTags(); |
46 // | 98 // |
47 // build cache | 99 // build cache |
69 System.arraycopy(tagLocalRevs, 0, copy, 0, x); | 121 System.arraycopy(tagLocalRevs, 0, copy, 0, x); |
70 tagLocalRevs = copy; | 122 tagLocalRevs = copy; |
71 } | 123 } |
72 System.out.printf("Prepared tag revisions to analyze: %d ms\n", System.currentTimeMillis() - start); | 124 System.out.printf("Prepared tag revisions to analyze: %d ms\n", System.currentTimeMillis() - start); |
73 // | 125 // |
126 final int[] counts = new int[2]; | |
127 HgManifest.Inspector emptyInsp = new HgManifest.Inspector() { | |
128 public boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision) { | |
129 counts[0]++; | |
130 return true; | |
131 } | |
132 public boolean next(Nodeid nid, String fname, String flags) { | |
133 counts[1]++; | |
134 return true; | |
135 } | |
136 public boolean end(int manifestRevision) { | |
137 return true; | |
138 } | |
139 }; | |
140 // final long start0 = System.currentTimeMillis(); | |
141 // repository.getManifest().walk(emptyInsp, tagLocalRevs[0]); // warm-up | |
142 // final long start1 = System.currentTimeMillis(); | |
143 // repository.getManifest().walk(emptyInsp, tagLocalRevs[0]); // warm-up | |
144 // counts[0] = counts[1] = 0; | |
145 // final long start2 = System.currentTimeMillis(); | |
146 // repository.getManifest().walk(emptyInsp, tagLocalRevs); | |
147 // // No-op iterate over selected revisions: 11719 ms (revs:189, files: 579652), warm-up: 218 ms. Cache built: 25281 ms | |
148 // // No-op iterate over selected revisions: 11719 ms (revs:189, files: 579652), warm-up1: 234 ms, warm-up2: 16 ms. Cache built: 25375 ms | |
149 // System.out.printf("No-op iterate over selected revisions: %d ms (revs:%d, files: %d), warm-up1: %d ms, warm-up2: %d ms \n", System.currentTimeMillis() - start2, counts[0], counts[1], start1-start0, start2-start1); | |
150 // | |
74 repository.getManifest().walk(new HgManifest.Inspector() { | 151 repository.getManifest().walk(new HgManifest.Inspector() { |
75 private int[] tagIndexAtRev = new int[4]; // it's unlikely there would be a lot of tags associated with a given cset | 152 private int[] tagIndexAtRev = new int[4]; // it's unlikely there would be a lot of tags associated with a given cset |
76 | 153 |
77 public boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision) { | 154 public boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision) { |
78 Nodeid cset = clogrmap.revision(changelogRevision); | 155 Nodeid cset = clogrmap.revision(changelogRevision); |