How to use sort method of org.junit.runners.ParentRunner class

Best junit code snippet using org.junit.runners.ParentRunner.sort

Run junit automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
1package org.junit.runners;
2
3import java.lang.annotation.Annotation;
4import java.util.ArrayList;
5import java.util.Collections;
6import java.util.Comparator;
7import java.util.Iterator;
8import java.util.List;
9import org.junit.AfterClass;
10import org.junit.BeforeClass;
11import org.junit.ClassRule;
12import org.junit.internal.AssumptionViolatedException;
13import org.junit.internal.runners.model.EachTestNotifier;
14import org.junit.internal.runners.rules.RuleFieldValidator;
15import org.junit.internal.runners.statements.RunAfters;
16import org.junit.internal.runners.statements.RunBefores;
17import org.junit.rules.RunRules;
18import org.junit.rules.TestRule;
19import org.junit.runner.Description;
20import org.junit.runner.Runner;
21import org.junit.runner.manipulation.Filter;
22import org.junit.runner.manipulation.Filterable;
23import org.junit.runner.manipulation.NoTestsRemainException;
24import org.junit.runner.manipulation.Sortable;
25import org.junit.runner.manipulation.Sorter;
26import org.junit.runner.notification.RunNotifier;
27import org.junit.runner.notification.StoppedByUserException;
28import org.junit.runners.model.FrameworkMethod;
29import org.junit.runners.model.InitializationError;
30import org.junit.runners.model.RunnerScheduler;
31import org.junit.runners.model.Statement;
32import org.junit.runners.model.TestClass;
33
34public abstract class ParentRunner<T> extends Runner implements Filterable, Sortable {
35    private List<T> fFilteredChildren;
36    private RunnerScheduler fScheduler;
37    private Sorter fSorter;
38    private final TestClass fTestClass;
39
40    /* renamed from: org.junit.runners.ParentRunner.3 */
41    class C07063 implements Runnable {
42        final /* synthetic */ Object val$each;
43        final /* synthetic */ RunNotifier val$notifier;
44
45        C07063(Object obj, RunNotifier runNotifier) {
46            this.val$each = obj;
47            this.val$notifier = runNotifier;
48        }
49
50        public void run() {
51            ParentRunner.this.runChild(this.val$each, this.val$notifier);
52        }
53    }
54
55    /* renamed from: org.junit.runners.ParentRunner.4 */
56    class C07074 implements Comparator<T> {
57        C07074() {
58        }
59
60        public int compare(T o1, T o2) {
61            return ParentRunner.this.fSorter.compare(ParentRunner.this.describeChild(o1), ParentRunner.this.describeChild(o2));
62        }
63    }
64
65    /* renamed from: org.junit.runners.ParentRunner.1 */
66    class C12691 implements RunnerScheduler {
67        C12691() {
68        }
69
70        public void schedule(Runnable childStatement) {
71            childStatement.run();
72        }
73
74        public void finished() {
75        }
76    }
77
78    /* renamed from: org.junit.runners.ParentRunner.2 */
79    class C12702 extends Statement {
80        final /* synthetic */ RunNotifier val$notifier;
81
82        C12702(RunNotifier runNotifier) {
83            this.val$notifier = runNotifier;
84        }
85
86        public void evaluate() {
87            ParentRunner.this.runChildren(this.val$notifier);
88        }
89    }
90
91    protected abstract Description describeChild(T t);
92
93    protected abstract List<T> getChildren();
94
95    protected abstract void runChild(T t, RunNotifier runNotifier);
96
97    protected ParentRunner(Class<?> testClass) throws InitializationError {
98        this.fSorter = Sorter.NULL;
99        this.fFilteredChildren = null;
100        this.fScheduler = new C12691();
101        this.fTestClass = new TestClass(testClass);
102        validate();
103    }
104
105    protected void collectInitializationErrors(List<Throwable> errors) {
106        validatePublicVoidNoArgMethods(BeforeClass.class, true, errors);
107        validatePublicVoidNoArgMethods(AfterClass.class, true, errors);
108        validateClassRules(errors);
109    }
110
111    protected void validatePublicVoidNoArgMethods(Class<? extends Annotation> annotation, boolean isStatic, List<Throwable> errors) {
112        for (FrameworkMethod eachTestMethod : getTestClass().getAnnotatedMethods(annotation)) {
113            eachTestMethod.validatePublicVoidNoArg(isStatic, errors);
114        }
115    }
116
117    private void validateClassRules(List<Throwable> errors) {
118        RuleFieldValidator.CLASS_RULE_VALIDATOR.validate(getTestClass(), errors);
119        RuleFieldValidator.CLASS_RULE_METHOD_VALIDATOR.validate(getTestClass(), errors);
120    }
121
122    protected Statement classBlock(RunNotifier notifier) {
123        return withClassRules(withAfterClasses(withBeforeClasses(childrenInvoker(notifier))));
124    }
125
126    protected Statement withBeforeClasses(Statement statement) {
127        List<FrameworkMethod> befores = this.fTestClass.getAnnotatedMethods(BeforeClass.class);
128        return befores.isEmpty() ? statement : new RunBefores(statement, befores, null);
129    }
130
131    protected Statement withAfterClasses(Statement statement) {
132        List<FrameworkMethod> afters = this.fTestClass.getAnnotatedMethods(AfterClass.class);
133        return afters.isEmpty() ? statement : new RunAfters(statement, afters, null);
134    }
135
136    private Statement withClassRules(Statement statement) {
137        List<TestRule> classRules = classRules();
138        return classRules.isEmpty() ? statement : new RunRules(statement, classRules, getDescription());
139    }
140
141    protected List<TestRule> classRules() {
142        List<TestRule> result = this.fTestClass.getAnnotatedMethodValues(null, ClassRule.class, TestRule.class);
143        result.addAll(this.fTestClass.getAnnotatedFieldValues(null, ClassRule.class, TestRule.class));
144        return result;
145    }
146
147    protected Statement childrenInvoker(RunNotifier notifier) {
148        return new C12702(notifier);
149    }
150
151    private void runChildren(RunNotifier notifier) {
152        for (T each : getFilteredChildren()) {
153            this.fScheduler.schedule(new C07063(each, notifier));
154        }
155        this.fScheduler.finished();
156    }
157
158    protected String getName() {
159        return this.fTestClass.getName();
160    }
161
162    public final TestClass getTestClass() {
163        return this.fTestClass;
164    }
165
166    protected final void runLeaf(Statement statement, Description description, RunNotifier notifier) {
167        EachTestNotifier eachNotifier = new EachTestNotifier(notifier, description);
168        eachNotifier.fireTestStarted();
169        try {
170            statement.evaluate();
171        } catch (AssumptionViolatedException e) {
172            eachNotifier.addFailedAssumption(e);
173        } catch (Throwable e2) {
174            eachNotifier.addFailure(e2);
175        } finally {
176            eachNotifier.fireTestFinished();
177        }
178    }
179
180    protected Annotation[] getRunnerAnnotations() {
181        return this.fTestClass.getAnnotations();
182    }
183
184    public Description getDescription() {
185        Description description = Description.createSuiteDescription(getName(), getRunnerAnnotations());
186        for (T child : getFilteredChildren()) {
187            description.addChild(describeChild(child));
188        }
189        return description;
190    }
191
192    public void run(RunNotifier notifier) {
193        EachTestNotifier testNotifier = new EachTestNotifier(notifier, getDescription());
194        try {
195            classBlock(notifier).evaluate();
196        } catch (AssumptionViolatedException e) {
197            testNotifier.fireTestIgnored();
198        } catch (StoppedByUserException e2) {
199            throw e2;
200        } catch (Throwable e3) {
201            testNotifier.addFailure(e3);
202        }
203    }
204
205    public void filter(Filter filter) throws NoTestsRemainException {
206        Iterator<T> iter = getFilteredChildren().iterator();
207        while (iter.hasNext()) {
208            T each = iter.next();
209            if (shouldRun(filter, each)) {
210                try {
211                    filter.apply(each);
212                } catch (NoTestsRemainException e) {
213                    iter.remove();
214                }
215            } else {
216                iter.remove();
217            }
218        }
219        if (getFilteredChildren().isEmpty()) {
220            throw new NoTestsRemainException();
221        }
222    }
223
224    public void sort(Sorter sorter) {
225        this.fSorter = sorter;
226        for (T each : getFilteredChildren()) {
227            sortChild(each);
228        }
229        Collections.sort(getFilteredChildren(), comparator());
230    }
231
232    private void validate() throws InitializationError {
233        List errors = new ArrayList();
234        collectInitializationErrors(errors);
235        if (!errors.isEmpty()) {
236            throw new InitializationError(errors);
237        }
238    }
239
240    private List<T> getFilteredChildren() {
241        if (this.fFilteredChildren == null) {
242            this.fFilteredChildren = new ArrayList(getChildren());
243        }
244        return this.fFilteredChildren;
245    }
246
247    private void sortChild(T child) {
248        this.fSorter.apply(child);
249    }
250
251    private boolean shouldRun(Filter filter, T each) {
252        return filter.shouldRun(describeChild(each));
253    }
254
255    private Comparator<? super T> comparator() {
256        return new C07074();
257    }
258
259    public void setScheduler(RunnerScheduler scheduler) {
260        this.fScheduler = scheduler;
261    }
262}
263
Full Screen
copy
1package com.zj.test.java.util;
2
3import com.zj.test.util.TestHelper;
4import org.junit.Test;
5
6import java.util.Arrays;
7import java.util.List;
8import java.util.Random;
9
10/* @author: zhoujian
11 * @qq: 2025513
12 * @create-time: 2020/10/23 17:32
13 * @description: java.util.Arrays常用api测试
14 * @version: 1.0
15 * @finished: true
16 * @finished-time: 2020年10月24日16:01:21
17 */
18public class ArraysTest {
19
20    /**
21     * 1.public static <T> java.util.List<T> asList(@NotNull T... a)
22     * 将给定的参数转换成一个List对象并返回,返回的List类型是Arrays内部实现类。
23     *
24     * <p>
25     * 注意:
26     * 1.返回类型不是java.util.ArrayList,而是Arrays实现的ArrayList同名静态内部类
27     * java.util.Arrays.ArrayList<E>: 该类只提供get,set方法,该类没有提供对add的支持,
28     * 如果调用add(..)方法会报错:
29     * java.lang.UnsupportedOperationException
30     * at java.util.AbstractList.add(AbstractList.java:148)
31     * at java.util.AbstractList.add(AbstractList.java:108)
32     * at com.zj.test.java.util.ArraysTest.test1(ArraysTest.java:34)
33     * at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
34     * at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
35     * at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
36     * at java.lang.reflect.Method.invoke(Method.java:498)
37     * at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
38     * at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
39     * at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
40     * at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
41     * at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
42     * at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
43     * at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
44     * at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
45     * at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
46     * at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
47     * at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
48     * at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
49     * at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
50     * at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
51     * at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
52     * at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
53     * at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
54     * at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
55     *
56     * <p>
57     * 2.asLisdt(..)返回的List后续不能增加(add)、删 除(remove),可以进行查询(get),更新(set)。
58     */
59    @Test
60    public void asList() {
61        List<Integer> integers = Arrays.asList(1, 2, 3);
62
63        TestHelper.println(integers);//[1, 2, 3]
64        TestHelper.println(integers.size());//3
65        // java.lang.ArrayIndexOutOfBoundsException: 5
66        // integers.set(5,6);
67
68        // java.util.Arrays.ArrayList不支持的操作:java.lang.UnsupportedOperationException
69        //integers.add(4);
70        //TestHelper.println(integers);
71        //TestHelper.println(integers.size());
72
73        // java.lang.UnsupportedOperationException
74        //integers.remove(1);
75
76        //TestHelper.println(integers.get(1));//ok
77        //integers.set(1, 2); //ok
78        // asList参数为不同类型测试
79        TestHelper.startTest("asList参数为不同类型测试");
80        TestHelper.println(Arrays.asList(1, 1f, 2d, "hello", 'c'));
81    }
82
83    /**
84     * 2.
85     * ...copyOf(*,newLength)                用于数组复制的一系列方法
86     * 注意: 复制得到的数组长度newLength比较灵活,可比原来的数组长度长或短或等于
87     * 当newLength < 待复制的数组: 从待复制数组0位置开始复制newLength个元素。
88     * 该方法的缺点就是只能从0位置开始复制元素。copyOfRange可以解决这个问题
89     * <p>
90     * 注:不会修改原来的数组
91     */
92    @Test
93    public void copyOf() {
94        // 基础类型数组的复制,这里用int[]测试
95        int[] ints = {1, 2, 3, 4};
96        TestHelper.println("待复制的数组", Arrays.toString(ints));
97        TestHelper.println("待复制的数组长度", ints.length);
98        int[] copyInts = Arrays.copyOf(ints, ints.length);
99        TestHelper.println("复制得到的数组", Arrays.toString(copyInts));
100        TestHelper.println("复制得到的数组长度", copyInts.length);
101        TestHelper.println("是否为同一引用", ints == copyInts);
102    }
103
104    /**
105     * 3.int[] copyOfRange(@NotNull int[] original,int from,int to)
106     * 指定复制数组区间内的元素
107     * <p>
108     * from: 必须[0,length], 否则跑出异常
109     * to: to必须>=from
110     * <p>
111     * 注意:
112     * 1.被复制元素在原来数组中的位置是[from,to),需要注意的是to位置的元素不被复制。
113     * 2.from==to: 不会复制任何元素。
114     * <p>
115     * 注: 不会修改原来的数组
116     */
117    @Test
118    public void copyOfRange() {
119        int[] ints = {1, 2, 3, 4};
120        TestHelper.println("待复制的数组", Arrays.toString(ints));
121        TestHelper.println("待复制的数组长度", ints.length);
122
123        int[] ints1 = Arrays.copyOfRange(ints, 1, 1);
124        TestHelper.println("复制得到的数组", Arrays.toString(ints1));
125        TestHelper.println("复制得到的数组长度", ints1.length);
126    }
127
128    /**
129     * 4.public static boolean equals(@Nullable T[] a,@Nullable T[] a2)
130     * 比较两个数组是否相等, 相等的条件是长度和元素值都相等。
131     */
132    @Test
133    public void equals() {
134        int[] ints1 = {1, 2, 3, 4};
135        int[] ints2 = {1, 2, 3, 4};
136        int[] ints3 = {1, 2, 3, 4, 5};
137        int[] ints4 = {1, 2, 3};
138        TestHelper.println("equals({1,2,3,4},{1,2,3,4})", Arrays.equals(ints1, ints2));
139        TestHelper.println("equals({1,2,3,4},{1,2,3,4,5})", Arrays.equals(ints1, ints3));
140        TestHelper.println("equals({1,2,3,4},{1,2,3})", Arrays.equals(ints1, ints4));
141    }
142
143    /**
144     * 5.与equals相比, deppEquals可用来比较复杂类型。
145     */
146    @Test
147    public void deepEquals() {
148        String[] s1 = {"hello", "world"};
149        String[] s2 = {"hello", "world"};
150        TestHelper.println("deepEquals(\"hello\",\"world\",\"hello\",\"world\")", Arrays.deepEquals(s1, s2));
151    }
152
153    /**
154     * 6.fill系列方法用来填充替换原来的元素
155     * 2个参数的fill方法是替换所有元素,如 fill(int[] a,int val)
156     * 4个参数是fill方法是替换连续范围内的所有元素
157     * <p>
158     * 注意:fill()方法会修改原来的数组
159     */
160    @Test
161    public void fill() {
162        int[] ints = {1, 2, 3, 4, 5};
163        // 替换所有元素
164        Arrays.fill(ints, 5);
165        TestHelper.println("fill(ints,5)", Arrays.toString(ints));
166
167        // 替换范围元素
168        Arrays.fill(ints, 1, 5, 9);
169        TestHelper.println("fill(ints,1,5,9)", Arrays.toString(ints));
170    }
171
172    /**
173     * 7.hasCode()              计算数组hash值
174     */
175    @Test
176    public void testHasCode() {
177        int[] ints = {1, 2, 3, 4};
178        String[] ss = {"我", "爱", "Java"};
179        TestHelper.println("hasCode({1,2,3,4})", Arrays.hashCode(ints));
180        TestHelper.println("hasCode({\"我\",\"爱\",\"Java\"})", Arrays.hashCode(ss));
181    }
182
183    /**
184     * 8.void parallelSort(@NotNull T[] a)
185     * 可以对简单类型或复杂类型按照升序进行排序,该方法会对所有元素进行排序
186     * <p>
187     * void parallelSort(int[] a, int fromIndex, int toIndex)
188     * 可以对[fromIndex,toIndex)内的元素进行升序排序
189     * 注: toIndex元素不会被排序
190     * 为并行算法
191     */
192    @Test
193    public void parrelSort() {
194        int[] ints = {1, 3, 42, 56, 7, 8, 5};
195        Arrays.parallelSort(ints);
196        TestHelper.println("parallelSort({1,3,42,56,7,8,5}) ", Arrays.toString(ints));
197        int[] ints1 = {1, 3, 42, 56, 7, 8, 5};
198        Arrays.parallelSort(ints1, 2, 5);
199        TestHelper.println("parallelSort({1,3,42,56,7,8,5},2,4)", Arrays.toString(ints1));
200    }
201
202    /**
203     * 8.void sort(@NotNull T[] a)
204     * 可以对简单类型或复杂类型按照升序进行排序,该方法会对所有元素进行排序
205     * <p>
206     * void sort(int[] a, int fromIndex, int toIndex)
207     * 可以对[fromIndex,toIndex)内的元素进行升序排序
208     * 注: toIndex元素不会被排序
209     * 为串行算法
210     */
211    @Test
212    public void Sort() {
213    }
214
215    /**
216     * 9.String toString(T[])       将简单或复杂类型数组转换成String
217     * 返回格式形如: [2, 21, 32, 45, 5],字符串用"[]"包围,并且元素之间以','隔开。
218     */
219    @Test
220    public void testToString() {
221        int[] ints = {2, 21, 32, 45, 5};
222        TestHelper.println("toString(int[])", Arrays.toString(ints));
223    }
224
225    /**
226     * 10.* binarySearch(..)
227     * 二分查找,被查找数组必须经过排序, 如果满足查找的元素有多个,不能保证某一个先被查找到。
228     */
229    @Test
230    public void testBinarySearch() {
231        // wait for test
232    }
233
234    /**
235     * 11.sort()和parallelSort()性能对比
236     * <p>
237     * 数据量较少时,大约在2万条以内,sort排序更快。
238     * <p>
239     * 结论: 数据量少时,sort性能更佳。
240     */
241    @Test
242    public void testSort() {
243        /*
244        量级10000.0: sort用时: 10ms, parallelSort用时: 10ms
245        量级20000.0: sort用时: 5ms, parallelSort用时: 4ms
246        量级30000.0: sort用时: 9ms, parallelSort用时: 6ms
247        量级40000.0: sort用时: 12ms, parallelSort用时: 10ms
248        量级50000.0: sort用时: 15ms, parallelSort用时: 8ms
249        量级60000.0: sort用时: 30ms, parallelSort用时: 3ms
250        量级70000.0: sort用时: 27ms, parallelSort用时: 6ms
251        量级80000.0: sort用时: 30ms, parallelSort用时: 5ms
252        量级90000.0: sort用时: 28ms, parallelSort用时: 3ms
253        量级100000.0: sort用时: 15ms, parallelSort用时: 5ms
254        量级110000.0: sort用时: 16ms, parallelSort用时: 1ms
255        量级120000.0: sort用时: 14ms, parallelSort用时: 2ms
256        量级130000.0: sort用时: 16ms, parallelSort用时: 1ms
257        量级140000.0: sort用时: 19ms, parallelSort用时: 2ms
258        量级150000.0: sort用时: 18ms, parallelSort用时: 2ms
259        量级160000.0: sort用时: 24ms, parallelSort用时: 2ms
260        量级170000.0: sort用时: 25ms, parallelSort用时: 3ms
261        量级180000.0: sort用时: 22ms, parallelSort用时: 1ms
262        量级190000.0: sort用时: 28ms, parallelSort用时: 2ms
263        量级200000.0: sort用时: 27ms, parallelSort用时: 1ms
264        量级210000.0: sort用时: 29ms, parallelSort用时: 3ms
265        量级220000.0: sort用时: 32ms, parallelSort用时: 1ms
266        量级230000.0: sort用时: 32ms, parallelSort用时: 1ms
267        量级240000.0: sort用时: 32ms, parallelSort用时: 2ms
268        量级250000.0: sort用时: 33ms, parallelSort用时: 1ms
269        量级260000.0: sort用时: 38ms, parallelSort用时: 2ms
270        量级270000.0: sort用时: 35ms, parallelSort用时: 2ms
271        量级280000.0: sort用时: 38ms, parallelSort用时: 3ms
272        量级290000.0: sort用时: 46ms, parallelSort用时: 5ms
273        量级300000.0: sort用时: 48ms, parallelSort用时: 2ms
274        量级310000.0: sort用时: 49ms, parallelSort用时: 3ms
275        量级320000.0: sort用时: 80ms, parallelSort用时: 2ms
276        量级330000.0: sort用时: 67ms, parallelSort用时: 5ms
277        量级340000.0: sort用时: 53ms, parallelSort用时: 3ms
278        量级350000.0: sort用时: 54ms, parallelSort用时: 2ms
279        量级360000.0: sort用时: 77ms, parallelSort用时: 5ms
280        量级370000.0: sort用时: 60ms, parallelSort用时: 8ms
281        量级380000.0: sort用时: 58ms, parallelSort用时: 4ms
282        量级390000.0: sort用时: 54ms, parallelSort用时: 58ms
283        量级400000.0: sort用时: 61ms, parallelSort用时: 4ms
284        量级410000.0: sort用时: 67ms, parallelSort用时: 5ms
285        量级420000.0: sort用时: 66ms, parallelSort用时: 3ms
286        量级430000.0: sort用时: 61ms, parallelSort用时: 7ms
287        量级440000.0: sort用时: 56ms, parallelSort用时: 2ms
288        量级450000.0: sort用时: 56ms, parallelSort用时: 2ms
289        量级460000.0: sort用时: 57ms, parallelSort用时: 3ms
290        量级470000.0: sort用时: 57ms, parallelSort用时: 3ms
291        量级480000.0: sort用时: 60ms, parallelSort用时: 3ms
292        量级490000.0: sort用时: 60ms, parallelSort用时: 3ms
293        量级500000.0: sort用时: 61ms, parallelSort用时: 3ms
294        量级510000.0: sort用时: 61ms, parallelSort用时: 3ms
295        量级520000.0: sort用时: 64ms, parallelSort用时: 4ms
296        量级530000.0: sort用时: 66ms, parallelSort用时: 3ms
297        量级540000.0: sort用时: 66ms, parallelSort用时: 4ms
298        量级550000.0: sort用时: 68ms, parallelSort用时: 4ms
299        量级560000.0: sort用时: 68ms, parallelSort用时: 4ms
300        量级570000.0: sort用时: 71ms, parallelSort用时: 3ms
301        量级580000.0: sort用时: 71ms, parallelSort用时: 3ms
302        量级590000.0: sort用时: 72ms, parallelSort用时: 4ms
303        量级600000.0: sort用时: 74ms, parallelSort用时: 3ms
304        量级610000.0: sort用时: 76ms, parallelSort用时: 3ms
305        量级620000.0: sort用时: 78ms, parallelSort用时: 3ms
306        量级630000.0: sort用时: 78ms, parallelSort用时: 3ms
307        量级640000.0: sort用时: 80ms, parallelSort用时: 3ms
308        量级650000.0: sort用时: 79ms, parallelSort用时: 4ms
309        量级660000.0: sort用时: 86ms, parallelSort用时: 4ms
310        量级670000.0: sort用时: 89ms, parallelSort用时: 5ms
311        量级680000.0: sort用时: 87ms, parallelSort用时: 4ms
312        量级690000.0: sort用时: 89ms, parallelSort用时: 5ms
313        量级700000.0: sort用时: 96ms, parallelSort用时: 4ms
314        量级710000.0: sort用时: 95ms, parallelSort用时: 5ms
315        量级720000.0: sort用时: 92ms, parallelSort用时: 4ms
316        量级730000.0: sort用时: 95ms, parallelSort用时: 4ms
317        量级740000.0: sort用时: 94ms, parallelSort用时: 5ms
318        量级750000.0: sort用时: 97ms, parallelSort用时: 6ms
319        量级760000.0: sort用时: 98ms, parallelSort用时: 6ms
320        量级770000.0: sort用时: 97ms, parallelSort用时: 6ms
321        量级780000.0: sort用时: 96ms, parallelSort用时: 6ms
322        量级790000.0: sort用时: 100ms, parallelSort用时: 7ms
323        量级800000.0: sort用时: 103ms, parallelSort用时: 6ms
324        量级810000.0: sort用时: 115ms, parallelSort用时: 7ms
325        量级820000.0: sort用时: 116ms, parallelSort用时: 6ms
326        量级830000.0: sort用时: 110ms, parallelSort用时: 6ms
327        量级840000.0: sort用时: 104ms, parallelSort用时: 6ms
328        量级850000.0: sort用时: 106ms, parallelSort用时: 6ms
329        量级860000.0: sort用时: 114ms, parallelSort用时: 6ms
330        量级870000.0: sort用时: 114ms, parallelSort用时: 7ms
331        量级880000.0: sort用时: 120ms, parallelSort用时: 7ms
332        量级890000.0: sort用时: 120ms, parallelSort用时: 6ms
333        量级900000.0: sort用时: 121ms, parallelSort用时: 6ms
334        量级910000.0: sort用时: 117ms, parallelSort用时: 7ms
335        量级920000.0: sort用时: 118ms, parallelSort用时: 5ms
336        量级930000.0: sort用时: 119ms, parallelSort用时: 6ms
337        量级940000.0: sort用时: 119ms, parallelSort用时: 7ms
338        量级950000.0: sort用时: 123ms, parallelSort用时: 7ms
339        量级960000.0: sort用时: 138ms, parallelSort用时: 9ms
340        量级970000.0: sort用时: 144ms, parallelSort用时: 6ms
341        量级980000.0: sort用时: 129ms, parallelSort用时: 9ms
342        量级990000.0: sort用时: 127ms, parallelSort用时: 6ms
343        量级1000000.0: sort用时: 131ms, parallelSort用时: 7ms*/
344        float size = 1;
345        Random random = new Random();
346        for (; size <= 100; size += 1) {
347            int[] ints = new int[(int) (size * 10000)];
348            for (int i = 0; i < ints.length; i++) {
349                ints[i] = random.nextInt(ints.length + 1);
350            }
351            int[] intsclone = Arrays.copyOf(ints, ints.length);
352            long startTime = System.currentTimeMillis();
353            Arrays.sort(ints);
354            long useTime1 = System.currentTimeMillis() - startTime;
355            startTime = System.currentTimeMillis();
356            Arrays.parallelSort(ints);
357            long useTime2 = System.currentTimeMillis() - startTime;
358            TestHelper.println("量级" + (size * 10000), "sort用时: " + useTime1 + "ms, parallelSort用时: " + useTime2 + "ms");
359            Arrays.parallelSort(intsclone);
360        }
361    }
362}
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Trigger sort code on LambdaTest Cloud Grid

Execute automation tests with sort on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)