Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/MapTagsToFileRevisions.java @ 307:2f2ab5c27f41
Collect sort reverse indexes along with array sorting
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Sat, 24 Sep 2011 04:06:27 +0200 |
parents | 85b8efde5586 |
children | b9592e21176a |
comparison
equal
deleted
inserted
replaced
306:971baa95fb07 | 307:2f2ab5c27f41 |
---|---|
12 import org.tmatesoft.hg.core.HgChangeset; | 12 import org.tmatesoft.hg.core.HgChangeset; |
13 import org.tmatesoft.hg.core.HgChangesetHandler; | 13 import org.tmatesoft.hg.core.HgChangesetHandler; |
14 import org.tmatesoft.hg.core.HgException; | 14 import org.tmatesoft.hg.core.HgException; |
15 import org.tmatesoft.hg.core.HgLogCommand; | 15 import org.tmatesoft.hg.core.HgLogCommand; |
16 import org.tmatesoft.hg.core.Nodeid; | 16 import org.tmatesoft.hg.core.Nodeid; |
17 import org.tmatesoft.hg.internal.ArrayHelper; | |
17 import org.tmatesoft.hg.repo.HgChangelog; | 18 import org.tmatesoft.hg.repo.HgChangelog; |
18 import org.tmatesoft.hg.repo.HgDataFile; | 19 import org.tmatesoft.hg.repo.HgDataFile; |
19 import org.tmatesoft.hg.repo.HgLookup; | 20 import org.tmatesoft.hg.repo.HgLookup; |
20 import org.tmatesoft.hg.repo.HgManifest; | 21 import org.tmatesoft.hg.repo.HgManifest; |
21 import org.tmatesoft.hg.repo.HgRepository; | 22 import org.tmatesoft.hg.repo.HgRepository; |
34 // Static ================================================================= | 35 // Static ================================================================= |
35 | 36 |
36 public static void main(String[] args) throws Exception { | 37 public static void main(String[] args) throws Exception { |
37 MapTagsToFileRevisions m = new MapTagsToFileRevisions(); | 38 MapTagsToFileRevisions m = new MapTagsToFileRevisions(); |
38 System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory()); | 39 System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory()); |
39 // Pattern p = Pattern.compile("^doc/[^/]*?\\.[0-9]\\.(x|ht)ml"); | |
40 // System.out.println(p.matcher("doc/asd.2.xml").matches()); | |
41 // System.out.println(p.matcher("doc/zxc.6.html").matches()); | |
42 // m.collectTagsPerFile(); | 40 // m.collectTagsPerFile(); |
43 m.manifestWalk(); | 41 // m.manifestWalk(); |
42 // m.changelogWalk(); | |
43 m.revisionMap(); | |
44 m = null; | 44 m = null; |
45 System.gc(); | 45 System.gc(); |
46 System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory()); | 46 System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory()); |
47 } | 47 } |
48 | 48 |
49 /* | |
50 * Each 5000 revisions from cpython, total 15 revisions | |
51 * Direct clog.getLocalRevision: ~260 ms | |
52 * RevisionMap.localRevision: ~265 ms (almost 100% in #init()) | |
53 * each 1000'th revision, total 71 revision: 1 230 vs 270 | |
54 * each 2000'th revision, total 36 revision: 620 vs 270 | |
55 * each 3000'th revision, total 24 revision: 410 vs 275 | |
56 */ | |
57 private void revisionMap() throws Exception { | |
58 ArrayHelper ah = new ArrayHelper(); | |
59 final List<String> initial = Arrays.asList("d", "w", "k", "b", "c", "i", "a", "r", "e", "h"); | |
60 String[] a = (String[]) initial.toArray(); | |
61 ah.sort(a); | |
62 System.out.println(Arrays.toString(initial.toArray())); | |
63 System.out.println(Arrays.toString(a)); | |
64 System.out.println(Arrays.toString(ah.getReverse())); | |
65 Object[] rebuilt = new Object[a.length]; | |
66 for (int i = 0; i < a.length; i++) { | |
67 int indexInOriginal = ah.getReverse()[i]; | |
68 rebuilt[indexInOriginal-1] = a[i]; | |
69 } | |
70 System.out.println(Arrays.toString(rebuilt)); | |
71 // | |
72 final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython")); | |
73 final HgChangelog clog = repository.getChangelog(); | |
74 ArrayList<Nodeid> revisions = new ArrayList<Nodeid>(); | |
75 final int step = 5000; | |
76 for (int i = 0, top = clog.getLastRevision(); i < top; i += step) { | |
77 revisions.add(clog.getRevision(i)); | |
78 } | |
79 final long s1 = System.nanoTime(); | |
80 for (Nodeid n : revisions) { | |
81 int r = clog.getLocalRevision(n); | |
82 if (r % step != 0) { | |
83 throw new IllegalStateException(Integer.toString(r)); | |
84 } | |
85 } | |
86 System.out.printf("Direct lookup of %d revisions took %,d ns\n", revisions.size(), System.nanoTime() - s1); | |
87 HgChangelog.RevisionMap rmap = clog.new RevisionMap(); | |
88 final long s2 = System.nanoTime(); | |
89 rmap.init(); | |
90 final long s3 = System.nanoTime(); | |
91 for (Nodeid n : revisions) { | |
92 int r = rmap.localRevision(n); | |
93 if (r % step != 0) { | |
94 throw new IllegalStateException(Integer.toString(r)); | |
95 } | |
96 } | |
97 System.out.printf("RevisionMap time: %d ms, of that init() %,d ns\n", (System.nanoTime() - s2) / 1000000, s3 - s2); | |
98 } | |
99 | |
49 private void changelogWalk() throws Exception { | 100 private void changelogWalk() throws Exception { |
101 final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython")); | |
50 final long start = System.currentTimeMillis(); | 102 final long start = System.currentTimeMillis(); |
51 final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython")); | |
52 repository.getChangelog().all(new HgChangelog.Inspector() { | 103 repository.getChangelog().all(new HgChangelog.Inspector() { |
53 public int xx = 0; | 104 public int xx = 0; |
54 | 105 |
55 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) { | 106 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) { |
56 if (xx+revisionNumber < 0) { | 107 if (xx+revisionNumber < 0) { |