You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PathFilterGroupTest2.java 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /*
  2. * Copyright (C) 2013, Robin Rosenberg
  3. * and other copyright owners as documented in the project's IP log.
  4. *
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Distribution License v1.0 which
  7. * accompanies this distribution, is reproduced below, and is
  8. * available at http://www.eclipse.org/org/documents/edl-v10.php
  9. *
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials provided
  22. * with the distribution.
  23. *
  24. * - Neither the name of the Eclipse Foundation, Inc. nor the
  25. * names of its contributors may be used to endorse or promote
  26. * products derived from this software without specific prior
  27. * written permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  30. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  31. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  35. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  36. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  37. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  38. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  41. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42. */
  43. package org.eclipse.jgit.treewalk.filter;
  44. import static org.hamcrest.MatcherAssert.assertThat;
  45. import static org.hamcrest.Matchers.lessThan;
  46. import static org.junit.Assert.assertEquals;
  47. import java.io.IOException;
  48. import org.eclipse.jgit.dircache.DirCache;
  49. import org.eclipse.jgit.dircache.DirCacheEditor;
  50. import org.eclipse.jgit.dircache.DirCacheEntry;
  51. import org.eclipse.jgit.dircache.DirCacheIterator;
  52. import org.eclipse.jgit.errors.IncorrectObjectTypeException;
  53. import org.eclipse.jgit.errors.MissingObjectException;
  54. import org.eclipse.jgit.lib.FileMode;
  55. import org.eclipse.jgit.lib.ObjectReader;
  56. import org.eclipse.jgit.treewalk.TreeWalk;
  57. import org.junit.Test;
  58. /**
  59. * Performance test suite for PathFilterGroup
  60. */
  61. public class PathFilterGroupTest2 {
  62. private DirCache dc;
  63. private String[] paths = new String[100000];
  64. private TreeFilter pf;
  65. private String data;
  66. private long tInit;
  67. public void setup(int pathsize, int filtersize, String[] filters) {
  68. long t1 = System.nanoTime();
  69. String[] seed = { "abc", "def", "ghi", "jkl", "mno", "pqr", "stu",
  70. "vwx", "xyz", "\u00e5\u00e4\u00f6" };
  71. dc = DirCache.newInCore();
  72. DirCacheEditor ed = dc.editor();
  73. int pi = 0;
  74. B: for (String a : seed) {
  75. for (String b : seed) {
  76. for (String c : seed) {
  77. for (String d : seed) {
  78. for (String e : seed) {
  79. if (pi >= pathsize)
  80. break B;
  81. String p1 = a + "/" + b + "/" + c + "/" + d + "/"
  82. + e;
  83. paths[pi] = p1;
  84. ed.add(new DirCacheEditor.PathEdit(p1) {
  85. @Override
  86. public void apply(DirCacheEntry ent) {
  87. ent.setFileMode(FileMode.REGULAR_FILE);
  88. }
  89. });
  90. ++pi;
  91. }
  92. }
  93. }
  94. }
  95. }
  96. ed.finish();
  97. long t2 = System.nanoTime();
  98. if (filters != null)
  99. pf = PathFilterGroup.createFromStrings(filters);
  100. else {
  101. // System.out.println(dc.getEntryCount());
  102. String[] filterPaths = new String[filtersize];
  103. System.arraycopy(paths, pathsize - filtersize, filterPaths, 0,
  104. filtersize);
  105. pf = PathFilterGroup.createFromStrings(filterPaths);
  106. }
  107. long t3 = System.nanoTime();
  108. data = "PX\t" + (t2 - t1) / 1E9 + "\t" + (t3 - t2) / 1E9 + "\t";
  109. tInit = t2-t1;
  110. }
  111. public void test(int pathSize, int filterSize)
  112. throws MissingObjectException, IncorrectObjectTypeException,
  113. IOException {
  114. setup(pathSize, filterSize, null);
  115. data += pathSize + "\t" + filterSize + "\t";
  116. long t1 = System.nanoTime();
  117. TreeWalk tw = new TreeWalk((ObjectReader) null);
  118. tw.reset();
  119. tw.addTree(new DirCacheIterator(dc));
  120. tw.setFilter(pf);
  121. tw.setRecursive(true);
  122. int n = 0;
  123. while (tw.next())
  124. n++;
  125. long t2 = System.nanoTime();
  126. data += (t2 - t1) / 1E9;
  127. assertEquals(filterSize, n);
  128. }
  129. @SuppressWarnings("boxing")
  130. public void test(int pathSize, int expectedWalkCount, String... filters)
  131. throws MissingObjectException, IncorrectObjectTypeException,
  132. IOException {
  133. setup(pathSize, -1, filters);
  134. data += pathSize + "\t" + filters.length + "\t";
  135. long t1 = System.nanoTime();
  136. TreeWalk tw = new TreeWalk((ObjectReader) null);
  137. tw.reset();
  138. tw.addTree(new DirCacheIterator(dc));
  139. tw.setFilter(pf);
  140. tw.setRecursive(true);
  141. int n = 0;
  142. while (tw.next())
  143. n++;
  144. long t2 = System.nanoTime();
  145. data += (t2 - t1) / 1E9;
  146. assertEquals(expectedWalkCount, n);
  147. // Walk time should be (much) faster then setup time
  148. assertThat(t2 - t1, lessThan(tInit / 2));
  149. }
  150. @Test
  151. public void test1_1() throws MissingObjectException,
  152. IncorrectObjectTypeException, IOException {
  153. test(1, 1);
  154. }
  155. @Test
  156. public void test2_2() throws MissingObjectException,
  157. IncorrectObjectTypeException, IOException {
  158. test(2, 2);
  159. }
  160. @Test
  161. public void test10_10() throws MissingObjectException,
  162. IncorrectObjectTypeException, IOException {
  163. test(10, 10);
  164. }
  165. @Test
  166. public void test100_100() throws MissingObjectException,
  167. IncorrectObjectTypeException, IOException {
  168. test(100, 100);
  169. }
  170. @Test
  171. public void test1000_1000() throws MissingObjectException,
  172. IncorrectObjectTypeException, IOException {
  173. test(1000, 1000);
  174. }
  175. @Test
  176. public void test10000_10000() throws MissingObjectException,
  177. IncorrectObjectTypeException, IOException {
  178. test(10000, 10000);
  179. }
  180. @Test
  181. public void test100000_100000() throws MissingObjectException,
  182. IncorrectObjectTypeException, IOException {
  183. test(100000, 100000);
  184. }
  185. @Test
  186. public void test100000_10000() throws MissingObjectException,
  187. IncorrectObjectTypeException, IOException {
  188. test(100000, 10000);
  189. }
  190. @Test
  191. public void test100000_1000() throws MissingObjectException,
  192. IncorrectObjectTypeException, IOException {
  193. test(100000, 1000);
  194. }
  195. @Test
  196. public void test100000_100() throws MissingObjectException,
  197. IncorrectObjectTypeException, IOException {
  198. test(100000, 100);
  199. }
  200. @Test
  201. public void test100000_10() throws MissingObjectException,
  202. IncorrectObjectTypeException, IOException {
  203. test(100000, 10);
  204. }
  205. @Test
  206. public void test100000_1() throws MissingObjectException,
  207. IncorrectObjectTypeException, IOException {
  208. test(100000, 1);
  209. }
  210. @Test
  211. public void test10000_1F() throws MissingObjectException,
  212. IncorrectObjectTypeException, IOException {
  213. test(100000, 10000, "abc");
  214. }
  215. @Test
  216. public void test10000_L2() throws MissingObjectException,
  217. IncorrectObjectTypeException, IOException {
  218. test(100000, 20000, "abc", "def");
  219. }
  220. @Test
  221. public void test10000_L10() throws MissingObjectException,
  222. IncorrectObjectTypeException, IOException {
  223. test(100000, 10000, "\u00e5\u00e4\u00f6");
  224. }
  225. }