Exercise 4. XMLResource Save and Load Options
What This Exercise Is About
Using the generated code for the PurchaseOrder model, you will experiment how the serialization and deserialization performance is affected by the XMLResource save and load options.
For your reference, here again is the UML class diagram describing the purchase order model:

What You Should Be Able To Do
At the end of the lab, you should be able to:
- Better understand how the XMLResource save and load options can affect the performance of your applications.
- Create a test to execute simple performance mesuarements on your model.
Required Materials
- Eclipse 3.2
- Eclipse Modeling Framework (EMF) 2.2
General Advice / Warnings
- Eclipse conventions suggest naming plug-in projects with a fully qualified plug-in ID, such as com.example.po. Do not use dashes in project names - this will create invalid entries in your MANIFEST.MF file.
- Make sure you're using the IBM JDK or else have implemented the Sun JDK Crimson DOM bug workaround (http://eclipse.org/emf/downloads-xerces.php).
Exercise Instructions
This exercise is carried out entirely using the Eclipse Software Development Kit (SDK) version 3.2 with the Eclipse Modeling Framework (EMF) 2.2 installed into it. The exercise instructions refer to this product as either Eclipse or as "the workbench".
These instructions are located in the exercises/Exercise4_Save_Load_Options folder. If you browse into this location by expanding the folders, you should find one additional folder: org.eclipse.emf.tutorial.advanced.po. This is an Eclipse project that you will import into your workspace to complete this exercise.
You will need to use the class SaveLoadOptionsTest to perform this exercise. The purpose of this class is to provide a test that can be easily customized in order to measure the effects of the XMLResource save and load options. Basically, when executed, this class:
- Measures the time spent saving XMLResources
- Creates a resource in memory with a small number of instances of the PurchaseOrder model
- Saves the resource to an output stream multiple times, printing out the average of each save
- Repeats the steps above for a resource with more instances of the model.
- Measures the time spent loading XMLResources
- Creates a resource in memory with a small number of instances of the PurchaseOrder model
- Creates an input stream from the output stream created when the resource is saved
- Loads the resource from the input stream multiple times, printing out the average of each load
- Repeats the steps above for a resource with more instances of the model.
Directions
- See Exercise 1, Step A.
- See Exercise 1, Step B.
- Open the SaveLoadOptionsTest located in the org.eclipse.emf.tutorial.advanced.test package. A very handy way of doing this is to use the Java's perspective Ctrl+Shift+T shortcut, that can be used to open any Java type.
- Analyze the code paying special attention to:
- The saveModel and loadModel methods that you will change in order to exercise the different XMLResource options.
- The TEST_SAVE and TEST_LOAD constants that enable the different tests performed by this class.
- The NUMBER_OF_REPETITIONS constant that specifies how many times a resource is saved or loaded during one execution of the test.
- Select Run... from the Run toolbar drop-down or menu.
- Expand Java Application, select SaveLoadOptionsTest and click the Run.
- The test should run for a few minutes and output the save and load measurements. You should write down the numbers produced. They represent the time spent in each operation when only the default options are used.
- Uncomment the options available in the saveModel and loadModel methods and run the tests for various combinations of options.
- Write down the results and compare with the previous results.
One important remark to be made is that this is a very simplistic way of measuring the performance impacts of changing the save and load options. If the impact is not significant, the numbers will only be different if the amount of repetitions is much larger than the initial value proposed. In this case we would also need to consider the influence of the garbage collection and other Java intrinsic issues. A more robust approach would be to use a specialized tool to do the measurements.
Summary
You experimented with the XMLResource save and load options, measuring how they can affect the performance of an application.