/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. package com.hazelcast.core;
  17. import org.junit.After;
  18. import org.junit.Test;
  19. import org.junit.runner.RunWith;
  20. import java.util.Arrays;
  21. import static org.junit.Assert.assertTrue;
  22. @RunWith(com.hazelcast.util.RandomBlockJUnit4ClassRunner.class)
  23. public class ISetPerformance extends PerformanceTest {
  24. private ISet<String> set = Hazelcast.getSet("ISetPerformance");
  25. @After
  26. public void clear() {
  27. t.stop();
  28. t.printResult();
  29. set.clear();
  30. assertTrue(set.isEmpty());
  31. }
  32. @Test
  33. public void testSetAddSameValue() {
  34. String test = "testSetAddSameValue";
  35. t = new PerformanceTimer(test, ops);
  36. for (int i = 0; i < ops; ++i) {
  37. set.add("Hello World");
  38. }
  39. }
  40. @Test
  41. public void testSetAddDifferentValue() {
  42. String test = "testSetAddDifferentValue";
  43. t = new PerformanceTimer(test, ops);
  44. for (int i = 0; i < ops; ++i) {
  45. set.add("Hello" + i);
  46. }
  47. }
  48. @Test
  49. public void testSetAddAllSameValues() {
  50. String test = "testSetAddAllSameValues";
  51. String[] values = {"one", "two", "three", "four", "five"};
  52. t = new PerformanceTimer(test, ops);
  53. for (int i = 0; i < ops; ++i) {
  54. set.addAll(Arrays.asList(values));
  55. }
  56. }
  57. @Test
  58. public void testSetAddAllDifferentValues() {
  59. String test = "testListAddAllDifferentValues";
  60. t = new PerformanceTimer(test, ops);
  61. for (int i = 0; i < ops; ++i) {
  62. String[] values = {"one" + i, "two" + i, "three" + i, "four" + i, "five" + i};
  63. set.addAll(Arrays.asList(values));
  64. }
  65. }
  66. @Test
  67. public void testSetContains() {
  68. String test = "testSetContains";
  69. for (int i = 0; i < ops; ++i) {
  70. set.add("Hello" + i);
  71. }
  72. t = new PerformanceTimer(test, ops);
  73. for (int i = 0; i < ops; ++i) {
  74. set.contains("Hello" + i);
  75. }
  76. }
  77. @Test
  78. public void testSetContainsAll() {
  79. String test = "testSetContainsAll";
  80. for (int i = 0; i < ops; ++i) {
  81. String[] values = {"one" + i, "two" + i, "three" + i, "four" + i, "five" + i};
  82. set.addAll(Arrays.asList(values));
  83. }
  84. t = new PerformanceTimer(test, ops);
  85. for (int i = 0; i < ops; ++i) {
  86. String[] values = {"one" + i, "two" + i, "three" + i, "four" + i, "five" + i};
  87. set.containsAll(Arrays.asList(values));
  88. }
  89. }
  90. @Test
  91. public void testSetRemove() {
  92. String test = "testSetRemove";
  93. for (int i = 0; i < ops; ++i) {
  94. set.add("Hello" + i);
  95. }
  96. t = new PerformanceTimer(test, ops);
  97. for (int i = 0; i < ops; ++i) {
  98. set.remove("Hello" + i);
  99. }
  100. }
  101. @Test
  102. public void testSetRemoveAll() {
  103. String test = "testSetRemoveAll";
  104. ops /= 10;
  105. for (int i = 0; i < ops; ++i) {
  106. String[] values = {"one" + i, "two" + i, "three" + i, "four" + i, "five" + i};
  107. set.addAll(Arrays.asList(values));
  108. }
  109. t = new PerformanceTimer(test, ops);
  110. for (int i = 0; i < ops; ++i) {
  111. String[] values = {"one" + i, "two" + i, "three" + i, "four" + i, "five" + i};
  112. set.removeAll(Arrays.asList(values));
  113. }
  114. ops *= 10;
  115. }
  116. @Test
  117. public void testSetRetainAll() {
  118. String test = "testSetRetainAll";
  119. for (int i = 0; i < ops; ++i) {
  120. set.add("Hello" + i);
  121. }
  122. String[] values = {"Hello1", "Hello2", "Hello3", "Hello4", "Hello5"};
  123. t = new PerformanceTimer(test, ops);
  124. set.retainAll(Arrays.asList(values));
  125. }
  126. }