|
| 1 | +package workload.evaluation; |
| 2 | + |
| 3 | +import java.io.File; |
| 4 | +import java.util.ArrayList; |
| 5 | +import java.util.List; |
| 6 | + |
| 7 | +import org.eclipse.emf.common.util.URI; |
| 8 | +import org.eclipse.emf.ecore.resource.Resource; |
| 9 | +import org.eclipse.emf.ecore.resource.ResourceSet; |
| 10 | +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; |
| 11 | +import org.eclipse.emf.ecore.util.EcoreUtil; |
| 12 | +import org.junit.Before; |
| 13 | +import org.junit.Test; |
| 14 | + |
| 15 | +import graphite.textual.XtextXMIResourceFactoryImpl; |
| 16 | +import workload.Person; |
| 17 | +import workload.Project; |
| 18 | +import workload.WorkloadPackage; |
| 19 | + |
| 20 | +public class ConsistencyExecutionTime { |
| 21 | + |
| 22 | + @Before |
| 23 | + public void setup() throws Exception { |
| 24 | + WorkloadPackage.eINSTANCE.eClass(); |
| 25 | + } |
| 26 | + |
| 27 | + @Test |
| 28 | + public void renameReferenceExecutionTime() { |
| 29 | + |
| 30 | + List<Long> renameReferenceDurations = new ArrayList<Long>(); |
| 31 | + |
| 32 | + for (int i = 0; i < EvaluationData.NumberOfModels; i++) { |
| 33 | + |
| 34 | + List<Long> modelDurations = new ArrayList<Long>(); |
| 35 | + |
| 36 | + for (int j = 0; j < EvaluationData.Iterations; j++) { |
| 37 | + |
| 38 | + try { |
| 39 | + File file = new File(EvaluationData.GeneratedModelsDirectory + EvaluationData.ModelFileName + (i+1) + "." + EvaluationData.ModelExtension); |
| 40 | + URI uri = URI.createFileURI(file.getAbsolutePath()); |
| 41 | + ResourceSet resourceSet = new ResourceSetImpl(); |
| 42 | + resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(EvaluationData.ModelExtension, new XtextXMIResourceFactoryImpl()); |
| 43 | + Resource resource = resourceSet.createResource(uri); |
| 44 | + resource.load(null); |
| 45 | + |
| 46 | + Project project = (Project)resource.getContents().get(0); |
| 47 | + Person alice = project.getPeople().get(0); |
| 48 | + |
| 49 | + long startTime = System.nanoTime(); |
| 50 | + |
| 51 | + alice.setName("AliceX"); |
| 52 | + |
| 53 | + long endTime = System.nanoTime(); |
| 54 | + long duration = endTime - startTime; |
| 55 | + |
| 56 | + modelDurations.add(duration); |
| 57 | + |
| 58 | + resource.unload(); |
| 59 | + } |
| 60 | + catch (Exception e) { |
| 61 | + e.printStackTrace(); |
| 62 | + } |
| 63 | + |
| 64 | + } |
| 65 | + |
| 66 | + long averageModelDuration = modelDurations.stream().mapToLong(Long::longValue).sum() / (modelDurations.isEmpty() ? 1 : modelDurations.size()); |
| 67 | + |
| 68 | + renameReferenceDurations.add(averageModelDuration); |
| 69 | + |
| 70 | + System.out.println("RenameReferenceX Duration [" + (i+1) + "]: " + String.format("%.5f", (renameReferenceDurations.get(i) / 1_000_000_000.0))); |
| 71 | + } |
| 72 | + |
| 73 | + for (int i = 0; i < renameReferenceDurations.size(); i++) { |
| 74 | + System.out.println("RenameReference Duration [" + (i+1) + "]: " + String.format("%.5f", (renameReferenceDurations.get(i) / 1_000_000_000.0))); |
| 75 | + } |
| 76 | + |
| 77 | + } |
| 78 | + |
| 79 | + @Test |
| 80 | + public void deleteReferenceExecutionTime() { |
| 81 | + |
| 82 | + List<Long> deleteReferenceDurations = new ArrayList<Long>(); |
| 83 | + |
| 84 | + for (int i = 0; i < EvaluationData.NumberOfModels; i++) { |
| 85 | + |
| 86 | + List<Long> modelDurations = new ArrayList<Long>(); |
| 87 | + |
| 88 | + for (int j = 0; j < EvaluationData.Iterations; j++) { |
| 89 | + |
| 90 | + try { |
| 91 | + File file = new File(EvaluationData.GeneratedModelsDirectory + EvaluationData.ModelFileName + (i+1) + "." + EvaluationData.ModelExtension); |
| 92 | + URI uri = URI.createFileURI(file.getAbsolutePath()); |
| 93 | + ResourceSet resourceSet = new ResourceSetImpl(); |
| 94 | + resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(EvaluationData.ModelExtension, new XtextXMIResourceFactoryImpl()); |
| 95 | + Resource resource = resourceSet.createResource(uri); |
| 96 | + resource.load(null); |
| 97 | + |
| 98 | + Project project = (Project)resource.getContents().get(0); |
| 99 | + Person alice = project.getPeople().get(0); |
| 100 | + |
| 101 | + long startTime = System.nanoTime(); |
| 102 | + |
| 103 | + EcoreUtil.delete(alice); |
| 104 | + |
| 105 | + long endTime = System.nanoTime(); |
| 106 | + long duration = endTime - startTime; |
| 107 | + |
| 108 | + modelDurations.add(duration); |
| 109 | + |
| 110 | + resource.unload(); |
| 111 | + } |
| 112 | + catch (Exception e) { |
| 113 | + e.printStackTrace(); |
| 114 | + } |
| 115 | + |
| 116 | + } |
| 117 | + |
| 118 | + long averageModelDuration = modelDurations.stream().mapToLong(Long::longValue).sum() / (modelDurations.isEmpty() ? 1 : modelDurations.size()); |
| 119 | + |
| 120 | + deleteReferenceDurations.add(averageModelDuration); |
| 121 | + |
| 122 | + System.out.println("DeleteReferenceX Duration [" + (i+1) + "]: " + String.format("%.5f", (deleteReferenceDurations.get(i) / 1_000_000_000.0))); |
| 123 | + |
| 124 | + } |
| 125 | + |
| 126 | + for (int i = 0; i < deleteReferenceDurations.size(); i++) { |
| 127 | + System.out.println("DeleteReference Duration [" + (i+1) + "]: " + String.format("%.5f", (deleteReferenceDurations.get(i) / 1_000_000_000.0))); |
| 128 | + } |
| 129 | + |
| 130 | + } |
| 131 | + |
| 132 | + @Test |
| 133 | + public void deleteReferenceLargestModel() { |
| 134 | + |
| 135 | + try { |
| 136 | + File file = new File(EvaluationData.GeneratedModelsDirectory + EvaluationData.ModelFileName + 5 + "." + EvaluationData.ModelExtension); |
| 137 | + URI uri = URI.createFileURI(file.getAbsolutePath()); |
| 138 | + ResourceSet resourceSet = new ResourceSetImpl(); |
| 139 | + resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(EvaluationData.ModelExtension, new XtextXMIResourceFactoryImpl()); |
| 140 | + Resource resource = resourceSet.createResource(uri); |
| 141 | + resource.load(null); |
| 142 | + |
| 143 | + Project project = (Project)resource.getContents().get(0); |
| 144 | + Person alice = project.getPeople().get(0); |
| 145 | + |
| 146 | + long startTime = System.nanoTime(); |
| 147 | + |
| 148 | + EcoreUtil.delete(alice); |
| 149 | + |
| 150 | + long endTime = System.nanoTime(); |
| 151 | + long duration = endTime - startTime; |
| 152 | + |
| 153 | + System.out.println("DeleteReference Duration: " + String.format("%.5f", (duration / 1_000_000_000.0))); |
| 154 | + |
| 155 | + resource.unload(); |
| 156 | + } |
| 157 | + catch (Exception e) { |
| 158 | + e.printStackTrace(); |
| 159 | + } |
| 160 | + |
| 161 | + } |
| 162 | + |
| 163 | + @Test |
| 164 | + public void renameReferenceLargestModel() { |
| 165 | + |
| 166 | + try { |
| 167 | + File file = new File(EvaluationData.GeneratedModelsDirectory + EvaluationData.ModelFileName + 1 + "." + EvaluationData.ModelExtension); |
| 168 | + URI uri = URI.createFileURI(file.getAbsolutePath()); |
| 169 | + ResourceSet resourceSet = new ResourceSetImpl(); |
| 170 | + resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(EvaluationData.ModelExtension, new XtextXMIResourceFactoryImpl()); |
| 171 | + Resource resource = resourceSet.createResource(uri); |
| 172 | + resource.load(null); |
| 173 | + |
| 174 | + Project project = (Project)resource.getContents().get(0); |
| 175 | + Person alice = project.getPeople().get(0); |
| 176 | + |
| 177 | + long startTime = System.nanoTime(); |
| 178 | + |
| 179 | + alice.setName("AliceX"); |
| 180 | + |
| 181 | + long endTime = System.nanoTime(); |
| 182 | + long duration = endTime - startTime; |
| 183 | + |
| 184 | + System.out.println("RenameReference Duration: " + String.format("%.5f", (duration / 1_000_000_000.0))); |
| 185 | + |
| 186 | + resource.unload(); |
| 187 | + } |
| 188 | + catch (Exception e) { |
| 189 | + e.printStackTrace(); |
| 190 | + } |
| 191 | + |
| 192 | + } |
| 193 | + |
| 194 | +} |
0 commit comments