capabilities of the mobile device, compared to the
parsing of XML. Also, due to the different ways of
representing data structures (e.g. the characters used
to represent boundaries), how hierarchies are
constructed etc., it is expected that there is some
difference in performance.
It is also expected that some usage scenarios
might favour one of the data representation methods,
whereas others might favour the other method.
3.3 Test Framework
A JavaME MIDlet was developed which can request
data from a remote server. The data retrieved is
represented either in XML or JSON. The JSON
library used on the client side was JSON-J2ME
(http://tavon.org/work/JSON-J2ME), and the XML
parser used was the JavaMe port of NanoXML
(http://nanoxml.sourceforge.net/orig/kvm.html),
which is a DOM-style XML parser (i.e., creates an
in-memory representation of the XML document, as
opposed to an event-based parser). For future
studies, other parsers should be included as well.
The test cases used are:
• Parsing of many primitive elements
• Parsing of large elements
• Parsing of deep trees
• Parsing of array elements
3.4 Test Environments
All tests have been performed live on a Nokia N82
running in a MIDP 2.0 environment. The tests have
also been run in the Sun Wireless Toolkit Emulator.
By running in the emulated environment, the
processing capacity and memory of the host device,
and the variations of these according to
unpredictable behaviour of the device, become
closer to irrelevant, and have less influence on the
measurement results.
3.5 Results
3.5.1 Primitive Elements
This test consists of parsing JSON and XML
documents with an increasing number of primitive
elements. The results are seen in Figure 1 and Figure
2. The number of elements ranges from 10 to 5000
with 10 elements interval. All the elements are at the
same (second to top) level of the document. As can
be seen of the graph, there is no large difference in
the time spent processing XML or JSON in this
case. However, when run in the emulator with more
memory and processing power, it is evident that
JSON is performing better than XML. Both for
JSON and XML, the function is close to linear,
where the rate of increase in processing time is
approx. 17.9 for JSON, whereas for XML it is 21.2
(on the device).
3.5.2 Single Element with Increasing Size
This test consists of parsing JSON and XML
documents with one element of increasing size. The
results can be seen in Figure 3 (on device).
These functions are also linear, where the rate of
increase for JSON is close to 2.3, whereas for XML
it is close to 6.7.
3.5.3 Complex Structure/Deep Tree
This test consists of parsing JSON and XML
documents of increasing complexity. The
complexity is introduced by creating a tree of
primitive elements. The results can be seen in Figure
4. The function is in this case exponential for XML,
whereas it is linear for JSON. Running the same
case in the emulator, JSON (with rate of increase in
processing time at 0.37) is not visible in the same
graph as XML.
3.5.4 Array of Elements
The results of this test are seen in Figure 5 (device).
The graphs show that in this case, JSON also scales
much better with increasing size of the data structure
(array size).
3.5.5 Summary of Results and Discussion
In most of the cases used for this performance study,
JSON performs better than XML. Only in the case
with an increasing number of primitive elements is
XML close to the JSON performance, and in the
emulator with “unlimited” resources available JSON
still performs better.
The XML parser used in this analysis is a non-
validating one. It is reasonable to expect that the
difference in performance would be even larger if
JSON had been compared to a validating parser. In
this situation XML does not have any clear
advantages compared to JSON; both can be used to
represent the same type of data structures.
There are other selection criteria than
performance when selecting a data exchange format.
Readability is one. However, XML is marginally
more readable than JSON. There exists fewer
WINSYS 2008 - International Conference on Wireless Information Networks and Systems
238