PageRenderTime 12ms CodeModel.GetById 1ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/hazelcast/src/test/java/com/hazelcast/core/ISetPerformance.java

https://bitbucket.org/gabral6_gmailcom/hazelcast
Java | 141 lines | 111 code | 15 blank | 15 comment | 13 complexity | 79f636cfc326000062e0af30927f6252 MD5 | raw file
  1/*
  2 * Copyright (c) 2008-2013, Hazelcast, Inc. All Rights Reserved.
  3 *
  4 * Licensed under the Apache License, Version 2.0 (the "License");
  5 * you may not use this file except in compliance with the License.
  6 * You may obtain a copy of the License at
  7 *
  8 * http://www.apache.org/licenses/LICENSE-2.0
  9 *
 10 * Unless required by applicable law or agreed to in writing, software
 11 * distributed under the License is distributed on an "AS IS" BASIS,
 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13 * See the License for the specific language governing permissions and
 14 * limitations under the License.
 15 */
 16
 17package com.hazelcast.core;
 18
 19import org.junit.After;
 20import org.junit.Test;
 21import org.junit.runner.RunWith;
 22
 23import java.util.Arrays;
 24
 25import static org.junit.Assert.assertTrue;
 26
 27@RunWith(com.hazelcast.util.RandomBlockJUnit4ClassRunner.class)
 28public class ISetPerformance extends PerformanceTest {
 29    private ISet<String> set = Hazelcast.getSet("ISetPerformance");
 30
 31    @After
 32    public void clear() {
 33        t.stop();
 34        t.printResult();
 35        set.clear();
 36        assertTrue(set.isEmpty());
 37    }
 38
 39    @Test
 40    public void testSetAddSameValue() {
 41        String test = "testSetAddSameValue";
 42        t = new PerformanceTimer(test, ops);
 43        for (int i = 0; i < ops; ++i) {
 44            set.add("Hello World");
 45        }
 46    }
 47
 48    @Test
 49    public void testSetAddDifferentValue() {
 50        String test = "testSetAddDifferentValue";
 51        t = new PerformanceTimer(test, ops);
 52        for (int i = 0; i < ops; ++i) {
 53            set.add("Hello" + i);
 54        }
 55    }
 56
 57    @Test
 58    public void testSetAddAllSameValues() {
 59        String test = "testSetAddAllSameValues";
 60        String[] values = {"one", "two", "three", "four", "five"};
 61        t = new PerformanceTimer(test, ops);
 62        for (int i = 0; i < ops; ++i) {
 63            set.addAll(Arrays.asList(values));
 64        }
 65    }
 66
 67    @Test
 68    public void testSetAddAllDifferentValues() {
 69        String test = "testListAddAllDifferentValues";
 70        t = new PerformanceTimer(test, ops);
 71        for (int i = 0; i < ops; ++i) {
 72            String[] values = {"one" + i, "two" + i, "three" + i, "four" + i, "five" + i};
 73            set.addAll(Arrays.asList(values));
 74        }
 75    }
 76
 77    @Test
 78    public void testSetContains() {
 79        String test = "testSetContains";
 80        for (int i = 0; i < ops; ++i) {
 81            set.add("Hello" + i);
 82        }
 83        t = new PerformanceTimer(test, ops);
 84        for (int i = 0; i < ops; ++i) {
 85            set.contains("Hello" + i);
 86        }
 87    }
 88
 89    @Test
 90    public void testSetContainsAll() {
 91        String test = "testSetContainsAll";
 92        for (int i = 0; i < ops; ++i) {
 93            String[] values = {"one" + i, "two" + i, "three" + i, "four" + i, "five" + i};
 94            set.addAll(Arrays.asList(values));
 95        }
 96        t = new PerformanceTimer(test, ops);
 97        for (int i = 0; i < ops; ++i) {
 98            String[] values = {"one" + i, "two" + i, "three" + i, "four" + i, "five" + i};
 99            set.containsAll(Arrays.asList(values));
100        }
101    }
102
103    @Test
104    public void testSetRemove() {
105        String test = "testSetRemove";
106        for (int i = 0; i < ops; ++i) {
107            set.add("Hello" + i);
108        }
109        t = new PerformanceTimer(test, ops);
110        for (int i = 0; i < ops; ++i) {
111            set.remove("Hello" + i);
112        }
113    }
114
115    @Test
116    public void testSetRemoveAll() {
117        String test = "testSetRemoveAll";
118        ops /= 10;
119        for (int i = 0; i < ops; ++i) {
120            String[] values = {"one" + i, "two" + i, "three" + i, "four" + i, "five" + i};
121            set.addAll(Arrays.asList(values));
122        }
123        t = new PerformanceTimer(test, ops);
124        for (int i = 0; i < ops; ++i) {
125            String[] values = {"one" + i, "two" + i, "three" + i, "four" + i, "five" + i};
126            set.removeAll(Arrays.asList(values));
127        }
128        ops *= 10;
129    }
130
131    @Test
132    public void testSetRetainAll() {
133        String test = "testSetRetainAll";
134        for (int i = 0; i < ops; ++i) {
135            set.add("Hello" + i);
136        }
137        String[] values = {"Hello1", "Hello2", "Hello3", "Hello4", "Hello5"};
138        t = new PerformanceTimer(test, ops);
139        set.retainAll(Arrays.asList(values));
140    }
141}