<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Javatech &#187; Benchmarks</title>
	<atom:link href="http://javatech.org/category/benchmarks/feed/" rel="self" type="application/rss+xml" />
	<link>http://javatech.org</link>
	<description>The Bleeding Edge of Java Technology</description>
	<lastBuildDate>Wed, 24 Jun 2009 22:30:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Collections Performance Benchmarks</title>
		<link>http://javatech.org/2008/03/collections-performance-benchmarks/</link>
		<comments>http://javatech.org/2008/03/collections-performance-benchmarks/#comments</comments>
		<pubDate>Tue, 25 Mar 2008 04:58:26 +0000</pubDate>
		<dc:creator>deevis</dc:creator>
				<category><![CDATA[Benchmarks]]></category>
		<category><![CDATA[JDK]]></category>

		<guid isPermaLink="false">http://javatech.org/2008/03/25/collections-performance-benchmarks/</guid>
		<description><![CDATA[I&#8217;ve been having fun of late pitting some Collections implementations against each other and getting some pretty peculiar results coming back.  Well, I guess the only thing peculiar about them is that Vector keeps out performing ArrayList, even though Vector is synchronized and ArrayList in theory should be faster.  So, one way that [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been having fun of late pitting some Collections implementations against each other and getting some pretty peculiar results coming back.  Well, I guess the only thing peculiar about them is that Vector keeps out performing ArrayList, even though Vector is synchronized and ArrayList in theory should be faster.  So, one way that ArrayList can lose is when the two aren&#8217;t sized correctly upon construction and have to grow to accommodate their datasets.   ArrayList grows by 50% with each resize, while Vector doubles.  Having to resize is an expensive operation and this explains quite a bit.  But even when I remove the resizing ( by sizing correctly upon construction ) ArrayList still gets pwned by Vector?  Here&#8217;s the results from a test with random 40-character Strings being built into a unique Collection where the Collections are sized <a href="http://javatech.org/wp-content/uploads/2008/03/building_unique_collection_of_random-generated_40_character_strings_-_every_element_appears_twice_-_presized_2008_03_23__11_52_am.png" title="Collections Showdown - presized"><img src="http://javatech.org/wp-content/uploads/2008/03/building_unique_collection_of_random-generated_40_character_strings_-_every_element_appears_twice_-_presized_2008_03_23__11_52_am.png" alt="Collections Showdown - presized" /></a>.correctly.  Notice how Vector and LinkedList perform virtually exactly the same, but ArrayList is slower, and getting slower as the dataset size increases.  Of course, HashSet is still the hands down winner and what you should use when working with Collections that don&#8217;t care about ordering.  TreeSet is a close second, but bear in mind that TreeSet can perform poorly when your dataset have similar Strings.</p>
<p>So, now it&#8217;s time to dig a bit deeper into the entire ArrayList versus Vector thing.  What if I build each of them up with integers from 1 to x before the test runs, and then as the test call contains() on each integer 1 to x?  Is contains faster or slower for ArrayList?</p>
<p><a href="http://javatech.org/wp-content/uploads/2008/03/calling_contains_on_every_element_of_different_sized_datasets_2008_03_23__10_28_pm.png" title="ArrayList vs Vector - add"><img src="http://javatech.org/wp-content/uploads/2008/03/calling_contains_on_every_element_of_different_sized_datasets_2008_03_23__10_28_pm.png" alt="ArrayList vs Vector - add" /></a></p>
<p>So, it looks like the calls to contains() are slower for ArrayList.  What about the calls to add() with a presized Collection?</p>
<p><a href="http://javatech.org/wp-content/uploads/2008/03/calling_add_x_number_of_times__presized_collections__2008_03_23__09_33_pm.png" title="calling_add_x_number_of_times__presized_collections__2008_03_23__09_33_pm.png"><img src="http://javatech.org/wp-content/uploads/2008/03/calling_add_x_number_of_times__presized_collections__2008_03_23__09_33_pm.png" alt="calling_add_x_number_of_times__presized_collections__2008_03_23__09_33_pm.png" /></a></p>
<p>Yet again, Vector is a little bit faster than ArrayList!  I&#8217;ve looked through the Java source code and so help me I swear the y are doing the same effective work &#8211; but Vector is synchronized and SHOULD BE SLOWER!</p>
<p>So, now I need to branch out and do some testing on other JDK&#8217;s and other OS&#8217;s.  1.5 and Linux, here I come!</p>
]]></content:encoded>
			<wfw:commentRss>http://javatech.org/2008/03/collections-performance-benchmarks/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The cost of Autoboxing</title>
		<link>http://javatech.org/2008/03/the-cost-of-autoboxing/</link>
		<comments>http://javatech.org/2008/03/the-cost-of-autoboxing/#comments</comments>
		<pubDate>Sat, 15 Mar 2008 06:36:52 +0000</pubDate>
		<dc:creator>deevis</dc:creator>
				<category><![CDATA[Benchmarks]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://javatech.org/2008/03/15/the-cost-of-autoboxing/</guid>
		<description><![CDATA[Simple question: How expensive is autoboxing of int/Integer types?
Simple answer: 15 nanoseconds per boxing.
No autoboxing ( ints only )
[source:java]
	public void runInternalTrial() throws Exception {
		int i = getRandomWithoutAutobox();
	}
	public int getRandomWithoutAutobox() {
		return rnd.nextInt(1000);
	}
[/source]
Autoboxing
[source:java]
	public void runInternalTrial() throws Exception {
		int i = getRandom();
	}
	// Will Autobox an int to an Integer&#8230;
	public Integer getRandom() {
		return rnd.nextInt(1000);
	}
[/source]
Note that the Autoboxing example has [...]]]></description>
			<content:encoded><![CDATA[<p>Simple question: How expensive is autoboxing of int/Integer types?<br />
Simple answer: 15 nanoseconds per boxing.</p>
<p><b>No autoboxing ( ints only )</b><br />
[source:java]<br />
	public void runInternalTrial() throws Exception {<br />
		int i = getRandomWithoutAutobox();<br />
	}</p>
<p>	public int getRandomWithoutAutobox() {<br />
		return rnd.nextInt(1000);<br />
	}<br />
[/source]<br />
<b>Autoboxing</b><br />
[source:java]<br />
	public void runInternalTrial() throws Exception {<br />
		int i = getRandom();<br />
	}</p>
<p>	// Will Autobox an int to an Integer&#8230;<br />
	public Integer getRandom() {<br />
		return rnd.nextInt(1000);<br />
	}<br />
[/source]<br />
Note that the Autoboxing example has to Autobox the value returned by getRandom to an Integer and then the caller has to then unbox this back to an int primitive.  The two examples for HalfBoxing are simply Autoboxing and then not unboxing back to an int.  Here are the results:<br />
<a href='http://javatech.org/wp-content/uploads/2008/03/java_autoboxing_2008_03_12__02_07_am.png' title='java_autoboxing_2008_03_12__02_07_am.png'><img src='http://javatech.org/wp-content/uploads/2008/03/java_autoboxing_2008_03_12__02_07_am.thumbnail.png' alt='java_autoboxing_2008_03_12__02_07_am.png' /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://javatech.org/2008/03/the-cost-of-autoboxing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building a unique collection of strings</title>
		<link>http://javatech.org/2008/03/lots-of-benchmark-results/</link>
		<comments>http://javatech.org/2008/03/lots-of-benchmark-results/#comments</comments>
		<pubDate>Tue, 04 Mar 2008 15:18:17 +0000</pubDate>
		<dc:creator>deevis</dc:creator>
				<category><![CDATA[Benchmarks]]></category>

		<guid isPermaLink="false">http://javatech.org/?p=36</guid>
		<description><![CDATA[I recently encountered some Java code that was building a unique list of String objects in order to prevent multiple processing of any of them.  The code was using an ArrayList and would make a call to contains() to determine whether or not to add each String.  I knew this wasn&#8217;t the optimal [...]]]></description>
			<content:encoded><![CDATA[<p>I recently encountered some Java code that was building a unique list of String objects in order to prevent multiple processing of any of them.  The code was using an ArrayList and would make a call to contains() to determine whether or not to add each String.  I knew this wasn&#8217;t the optimal way of doing it and wanted to immediately change the implementation to use HashSet, but figured I&#8217;d benchmark it and learn exactly what I&#8217;m dealing with.  In addition to benchmarking the ArrayList implementation and a HashSet implementation, I also threw a TreeSet and the new java.util.concurrent.ConcurrentSkipListSet into the mix.  What do you think?  Which will be the fastest between HashSet, TreeSet and ArrayList implementations?</p>
<p><strong>ArrayList</strong></p>
<p>[source:java]<br />
	public void runInternalTrial() throws Exception {<br />
		List<string> list = new ArrayList<string>();<br />
		int count = 0;<br />
		while ( count < getWorkload() ) {<br />
			for ( String s : data ) {<br />
				if ( ! list.contains( s )) {<br />
					list.add( s );<br />
				}<br />
				count++;<br />
				if ( count >= getWorkload() ) break;<br />
			}<br />
		}<br />
	}</p>
<p>[/source]</p>
<p><strong>HashSet</strong></p>
<p>[source:java]<br />
	public void runInternalTrial() throws Exception {<br />
		Set<string> set = new HashSet<string>();<br />
		int count = 0;<br />
		while ( count < getWorkload() ) {<br />
			for ( String s : data ) {<br />
				set.add( s );<br />
				count++;<br />
				if ( count >= getWorkload() ) break;<br />
			}<br />
		}<br />
	}</p>
<p>[/source]</p>
<p>Here are the results:  ( on the time axis I&#8217;ve got the size of the data being processed )</p>
<p><a href="http://javatech.org/wp-content/uploads/2008/03/building_unique_collections_2008_03_13__02_55_am.png" title="Building a unique set of Strings"><img src="http://javatech.org/wp-content/uploads/2008/03/building_unique_collections_2008_03_13__02_55_am.png" alt="Building a unique set of Strings" /></a></p>
<p>Of interest from the results shown above is that the ArrayList implementation is actually faster for the extremely small data sizes of 5 &amp; 10.   I wasn&#8217;t exactly sure how the TreeSet would perform, but I thought it might out perform the ArrayList.  I guess this is generally going to be dependent on the nature of the data being processed.  HashSet, sure enough, is the hands down winner.  Even with the small sized datasets where ArrayList wins, the amounts are down in the hundreds of nanoseconds realm.  Once the size of the dataset hits ( still very small ) size 15, then HashSet is already 1,500 nanoseconds faster.</p>
<p>The new ConcurrentSkipListSet, while it is completely blown away performance-wise by even ArrayList and TreeSet, shouldn&#8217;t necessarily be counted out.  If the building of the unique list isn&#8217;t something that happens too often, then even the cost of an extra 30,000 nanoseconds isn&#8217;t going to be noticable.  If you are in your service layer and are using the ConcurrentSkipListSet to maintain state that may be accessed/mutated by multiple threads, the guaranteed thread safety may well be worth this extra speed cost.</p>
]]></content:encoded>
			<wfw:commentRss>http://javatech.org/2008/03/lots-of-benchmark-results/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Connection Pool Showdown</title>
		<link>http://javatech.org/2008/02/connection-pool-showdown/</link>
		<comments>http://javatech.org/2008/02/connection-pool-showdown/#comments</comments>
		<pubDate>Tue, 26 Feb 2008 15:00:54 +0000</pubDate>
		<dc:creator>deevis</dc:creator>
				<category><![CDATA[Benchmarks]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://javatech.org/?p=29</guid>
		<description><![CDATA[I put C3P0, DBCP, and Proxool to the test and confirmed that DBCP is the fastest pool in the West, so long as there isn&#8217;t any complicated synchronization being done by the code using DBCP!  C3P0, safe even with complicated synchronization and very, very configurable and robutst, came in a pretty close second.  [...]]]></description>
			<content:encoded><![CDATA[<p>I put C3P0, DBCP, and Proxool to the test and confirmed that DBCP is the fastest pool in the West, so long as there isn&#8217;t any complicated synchronization being done by the code using DBCP!  C3P0, safe even with complicated synchronization and very, very configurable and robutst, came in a pretty close second.  Proxool, the loser in this test, was surprisingly unable to deal with more threads requesting Connections than it&#8217;s maxSize.  It wouldn&#8217;t block, it would instantly throw an Exception.  SO, I made sure that the pool sizes for all 3 were larger than the number of threads which would be concurrently accessing the pools.</p>
<h2><a href="http://javatech.org/wp-content/uploads/2008/03/connection_pool_showdown_2008_03_12__07_36_am.png" title="C3P0, DBCP, and Proxool battle it out"><img src="http://javatech.org/wp-content/uploads/2008/03/connection_pool_showdown_2008_03_12__07_36_am.png" alt="C3P0, DBCP, and Proxool battle it out" /></a></h2>
<h3>Connection Pool Showdown</h3>
<div style='font-size:smaller;font-weight:bolder;'>JVM Version 1.6.0_05-ea<br />
Windows XP[x86] &#8211; 2 processors<br />
31.55MB/254.06MB Memory
</div>
<table border=1>
<tr>
<th>Benchmark</th>
<th>Threads</th>
<th>Avg Nanos</th>
<th>Slow Factor</th>
</tr>
<tr>
<td>DBCP</td>
<td>40</td>
<td>74092.28</td>
<td>1.00x</td>
</tr>
<tr>
<td>DBCP</td>
<td>30</td>
<td>75085.88</td>
<td>1.01x</td>
</tr>
<tr>
<td>DBCP</td>
<td>20</td>
<td>75230.27</td>
<td>1.02x</td>
</tr>
<tr>
<td>DBCP</td>
<td>10</td>
<td>76437.40</td>
<td>1.03x</td>
</tr>
<tr>
<td>C3P0</td>
<td>10</td>
<td>93405.98</td>
<td>1.26x</td>
</tr>
<tr>
<td>C3P0</td>
<td>30</td>
<td>94054.79</td>
<td>1.27x</td>
</tr>
<tr>
<td>C3P0</td>
<td>20</td>
<td>94087.60</td>
<td>1.27x</td>
</tr>
<tr>
<td>C3P0</td>
<td>40</td>
<td>94865.61</td>
<td>1.28x</td>
</tr>
<tr>
<td>DBCP</td>
<td>1</td>
<td>104907.12</td>
<td>1.42x</td>
</tr>
<tr>
<td>C3P0</td>
<td>1</td>
<td>116039.45</td>
<td>1.57x</td>
</tr>
<tr>
<td>Proxool</td>
<td>10</td>
<td>142769.39</td>
<td>1.93x</td>
</tr>
<tr>
<td>Proxool</td>
<td>20</td>
<td>143932.09</td>
<td>1.94x</td>
</tr>
<tr>
<td>Proxool</td>
<td>30</td>
<td>146066.93</td>
<td>1.97x</td>
</tr>
<tr>
<td>Proxool</td>
<td>40</td>
<td>148903.46</td>
<td>2.01x</td>
</tr>
<tr>
<td>Proxool</td>
<td>1</td>
<td>183513.91</td>
<td>2.48x</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://javatech.org/2008/02/connection-pool-showdown/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Log4J Conversion Pattern Performance</title>
		<link>http://javatech.org/2008/02/log4j-conversion-pattern-performance/</link>
		<comments>http://javatech.org/2008/02/log4j-conversion-pattern-performance/#comments</comments>
		<pubDate>Tue, 26 Feb 2008 14:59:31 +0000</pubDate>
		<dc:creator>deevis</dc:creator>
				<category><![CDATA[Benchmarks]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://javatech.org/?p=27</guid>
		<description><![CDATA[I&#8217;ve seen the warnings before in log4j&#8217;s documentation about the format directives %C, %F, %L, %l and %M, which give really useful information, but at a cost.  Well, what is the cost of using some of these settings?  What if I use them all, or none?  I just had to find out, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve seen the warnings before in log4j&#8217;s documentation about the format directives %C, %F, %L, %l and %M, which give really useful information, but at a cost.  Well, what is the cost of using some of these settings?  What if I use them all, or none?  I just had to find out, here are the results:</p>
<p><a href="http://javatech.org/wp-content/uploads/2008/03/log4j_conversion_patterns_2008_03_12__02_35_am.png" title="log4j_conversion_patterns_2008_03_12__02_35_am.png"><img src="http://javatech.org/wp-content/uploads/2008/03/log4j_conversion_patterns_2008_03_12__02_35_am.png" alt="log4j_conversion_patterns_2008_03_12__02_35_am.png" /></a></p>
<p>These results completely reinforce the fact that the expensive settings %F, %L and %C should not be used in your production environment.  In the unfortunate case that you use all of them, then you&#8217;re looking at ( already expensive ) logging calls taking 9 times longer, verging on millisecond timings.</p>
<h3>Log4J Conversion Patterns</h3>
<p style="font-size: smaller; font-weight: bolder">JVM Version 1.6.0_05-ea<br />
Windows XP[x86] &#8211; 2 processors<br />
5.46MB/63.56MB Memory</p>
<table border="1">
<tr>
<th>Benchmark</th>
<th>Threads</th>
<th>Avg Nanos</th>
<th>Slow Factor</th>
</tr>
<tr>
<td>Fast</td>
<td>1</td>
<td>28825.21</td>
<td>1.00x</td>
</tr>
<tr>
<td>Fast</td>
<td>15</td>
<td>31416.34</td>
<td>1.09x</td>
</tr>
<tr>
<td>Fast</td>
<td>20</td>
<td>32638.25</td>
<td>1.13x</td>
</tr>
<tr>
<td>Fast</td>
<td>5</td>
<td>33509.15</td>
<td>1.16x</td>
</tr>
<tr>
<td>Fast</td>
<td>10</td>
<td>33564.08</td>
<td>1.16x</td>
</tr>
<tr>
<td>Fast</td>
<td>35</td>
<td>34246.23</td>
<td>1.19x</td>
</tr>
<tr>
<td>Fast</td>
<td>50</td>
<td>36421.31</td>
<td>1.26x</td>
</tr>
<tr>
<td>Fast</td>
<td>40</td>
<td>39088.55</td>
<td>1.36x</td>
</tr>
<tr>
<td>Fast</td>
<td>30</td>
<td>39572.70</td>
<td>1.37x</td>
</tr>
<tr>
<td>Fast</td>
<td>45</td>
<td>42566.97</td>
<td>1.48x</td>
</tr>
<tr>
<td>Fast</td>
<td>25</td>
<td>44669.52</td>
<td>1.55x</td>
</tr>
<tr>
<td>%F:%L</td>
<td>1</td>
<td>99596.84</td>
<td>3.46x</td>
</tr>
<tr>
<td>%C:%F:%L</td>
<td>1</td>
<td>109776.19</td>
<td>3.81x</td>
</tr>
<tr>
<td>%F:%L</td>
<td>15</td>
<td>120370.05</td>
<td>4.18x</td>
</tr>
<tr>
<td>%F:%L</td>
<td>20</td>
<td>121903.60</td>
<td>4.23x</td>
</tr>
<tr>
<td>%F:%L</td>
<td>5</td>
<td>122038.00</td>
<td>4.23x</td>
</tr>
<tr>
<td>%F:%L</td>
<td>25</td>
<td>125623.38</td>
<td>4.36x</td>
</tr>
<tr>
<td>%F:%L</td>
<td>35</td>
<td>126799.53</td>
<td>4.40x</td>
</tr>
<tr>
<td>%C:%F:%L</td>
<td>10</td>
<td>127100.32</td>
<td>4.41x</td>
</tr>
<tr>
<td>%F:%L</td>
<td>30</td>
<td>128148.09</td>
<td>4.45x</td>
</tr>
<tr>
<td>%F:%L</td>
<td>40</td>
<td>128208.69</td>
<td>4.45x</td>
</tr>
<tr>
<td>%C:%F:%L</td>
<td>20</td>
<td>131857.94</td>
<td>4.57x</td>
</tr>
<tr>
<td>%F:%L</td>
<td>50</td>
<td>133799.33</td>
<td>4.64x</td>
</tr>
<tr>
<td>%F:%L</td>
<td>10</td>
<td>133837.24</td>
<td>4.64x</td>
</tr>
<tr>
<td>%C:%F:%L</td>
<td>25</td>
<td>134114.84</td>
<td>4.65x</td>
</tr>
<tr>
<td>%F:%L</td>
<td>45</td>
<td>134969.59</td>
<td>4.68x</td>
</tr>
<tr>
<td>%C:%F:%L</td>
<td>35</td>
<td>135091.85</td>
<td>4.69x</td>
</tr>
<tr>
<td>%C:%F:%L</td>
<td>15</td>
<td>138423.94</td>
<td>4.80x</td>
</tr>
<tr>
<td>%C:%F:%L</td>
<td>30</td>
<td>139919.54</td>
<td>4.85x</td>
</tr>
<tr>
<td>%C:%F:%L</td>
<td>5</td>
<td>142347.28</td>
<td>4.94x</td>
</tr>
<tr>
<td>%C:%F:%L</td>
<td>45</td>
<td>144215.52</td>
<td>5.00x</td>
</tr>
<tr>
<td>%C:%F:%L</td>
<td>40</td>
<td>144652.90</td>
<td>5.02x</td>
</tr>
<tr>
<td>%C:%F:%L</td>
<td>50</td>
<td>155159.06</td>
<td>5.38x</td>
</tr>
<tr>
<td>ALL</td>
<td>45</td>
<td>260584.64</td>
<td>9.04x</td>
</tr>
<tr>
<td>ALL</td>
<td>15</td>
<td>260779.51</td>
<td>9.05x</td>
</tr>
<tr>
<td>ALL</td>
<td>40</td>
<td>263862.17</td>
<td>9.15x</td>
</tr>
<tr>
<td>ALL</td>
<td>1</td>
<td>264690.88</td>
<td>9.18x</td>
</tr>
<tr>
<td>ALL</td>
<td>25</td>
<td>266042.80</td>
<td>9.23x</td>
</tr>
<tr>
<td>ALL</td>
<td>35</td>
<td>267562.76</td>
<td>9.28x</td>
</tr>
<tr>
<td>ALL</td>
<td>5</td>
<td>270316.00</td>
<td>9.38x</td>
</tr>
<tr>
<td>ALL</td>
<td>50</td>
<td>272006.58</td>
<td>9.44x</td>
</tr>
<tr>
<td>ALL</td>
<td>10</td>
<td>276599.74</td>
<td>9.60x</td>
</tr>
<tr>
<td>ALL</td>
<td>30</td>
<td>277064.42</td>
<td>9.61x</td>
</tr>
<tr>
<td>ALL</td>
<td>20</td>
<td>286092.27</td>
<td>9.93x</td>
</tr>
</table>
<p>But, then, how long does the individual usage of the perpetrators cost?  I ran that one, too.  Here are the results:<br />
<a href='http://javatech.org/wp-content/uploads/2008/03/log4j_conversion_patterns_2008_03_15__12_25_pm.png' title='log4j_conversion_patterns_2008_03_15__12_25_pm.png'><img src='http://javatech.org/wp-content/uploads/2008/03/log4j_conversion_patterns_2008_03_15__12_25_pm.png' alt='log4j_conversion_patterns_2008_03_15__12_25_pm.png' /></a></p>
<p>%l is the most expensive conversion pattern.  On average it takes an extra 140,000 nanoseconds.<br />
%C is the next most expensive, taking about 110,000 nanoseconds longer.<br />
The rest ( %M, %F, %L ) each take about 100,000 nanoseconds longer.</p>
<p>Now you know.</p>
<h3>Log4J Conversion Patterns</h3>
<div style='font-size:smaller;font-weight:bolder;'>JVM Version 1.6.0_05-ea<br />
Windows XP[x86] &#8211; 2 processors<br />
4.94MB/63.56MB Memory
</div>
<table border=1>
<tr>
<th>Benchmark</th>
<th>Threads</th>
<th>Avg Nanos</th>
<th>Slow Factor</th>
</tr>
<tr>
<td>Fast</td>
<td>30</td>
<td>33106.79</td>
<td>1.00x</td>
</tr>
<tr>
<td>Fast</td>
<td>35</td>
<td>36082.72</td>
<td>1.09x</td>
</tr>
<tr>
<td>Fast</td>
<td>20</td>
<td>37435.39</td>
<td>1.13x</td>
</tr>
<tr>
<td>Fast</td>
<td>40</td>
<td>37615.85</td>
<td>1.14x</td>
</tr>
<tr>
<td>Fast</td>
<td>10</td>
<td>40022.65</td>
<td>1.21x</td>
</tr>
<tr>
<td>Fast</td>
<td>1</td>
<td>40961.19</td>
<td>1.24x</td>
</tr>
<tr>
<td>Fast</td>
<td>25</td>
<td>41009.21</td>
<td>1.24x</td>
</tr>
<tr>
<td>Fast</td>
<td>45</td>
<td>41631.96</td>
<td>1.26x</td>
</tr>
<tr>
<td>Fast</td>
<td>50</td>
<td>42989.00</td>
<td>1.30x</td>
</tr>
<tr>
<td>Fast</td>
<td>15</td>
<td>46050.36</td>
<td>1.39x</td>
</tr>
<tr>
<td>Fast</td>
<td>5</td>
<td>50155.79</td>
<td>1.51x</td>
</tr>
<tr>
<td>%M </td>
<td>5</td>
<td>126486.35</td>
<td>3.82x</td>
</tr>
<tr>
<td>%L</td>
<td>15</td>
<td>132137.75</td>
<td>3.99x</td>
</tr>
<tr>
<td>%L</td>
<td>35</td>
<td>134056.48</td>
<td>4.05x</td>
</tr>
<tr>
<td>%L</td>
<td>40</td>
<td>134538.77</td>
<td>4.06x</td>
</tr>
<tr>
<td>%M </td>
<td>15</td>
<td>135388.24</td>
<td>4.09x</td>
</tr>
<tr>
<td>%F</td>
<td>10</td>
<td>137914.76</td>
<td>4.17x</td>
</tr>
<tr>
<td>%L</td>
<td>5</td>
<td>138189.31</td>
<td>4.17x</td>
</tr>
<tr>
<td>%L</td>
<td>25</td>
<td>138781.50</td>
<td>4.19x</td>
</tr>
<tr>
<td>%F</td>
<td>15</td>
<td>139051.26</td>
<td>4.20x</td>
</tr>
<tr>
<td>%L</td>
<td>10</td>
<td>139648.04</td>
<td>4.22x</td>
</tr>
<tr>
<td>%F</td>
<td>25</td>
<td>139736.45</td>
<td>4.22x</td>
</tr>
<tr>
<td>%L</td>
<td>20</td>
<td>140881.53</td>
<td>4.26x</td>
</tr>
<tr>
<td>%M </td>
<td>10</td>
<td>140943.95</td>
<td>4.26x</td>
</tr>
<tr>
<td>%F</td>
<td>20</td>
<td>142361.85</td>
<td>4.30x</td>
</tr>
<tr>
<td>%M </td>
<td>20</td>
<td>142539.18</td>
<td>4.31x</td>
</tr>
<tr>
<td>%M </td>
<td>25</td>
<td>142656.80</td>
<td>4.31x</td>
</tr>
<tr>
<td>%C </td>
<td>20</td>
<td>143221.29</td>
<td>4.33x</td>
</tr>
<tr>
<td>%M </td>
<td>30</td>
<td>143781.90</td>
<td>4.34x</td>
</tr>
<tr>
<td>%F</td>
<td>5</td>
<td>143855.32</td>
<td>4.35x</td>
</tr>
<tr>
<td>%L</td>
<td>30</td>
<td>144129.23</td>
<td>4.35x</td>
</tr>
<tr>
<td>%M </td>
<td>40</td>
<td>144481.16</td>
<td>4.36x</td>
</tr>
<tr>
<td>%F</td>
<td>35</td>
<td>145803.89</td>
<td>4.40x</td>
</tr>
<tr>
<td>%F</td>
<td>30</td>
<td>145891.32</td>
<td>4.41x</td>
</tr>
<tr>
<td>%C </td>
<td>10</td>
<td>147103.22</td>
<td>4.44x</td>
</tr>
<tr>
<td>%F</td>
<td>45</td>
<td>148460.17</td>
<td>4.48x</td>
</tr>
<tr>
<td>%L</td>
<td>45</td>
<td>148951.05</td>
<td>4.50x</td>
</tr>
<tr>
<td>%C </td>
<td>25</td>
<td>149877.80</td>
<td>4.53x</td>
</tr>
<tr>
<td>%F</td>
<td>50</td>
<td>150231.08</td>
<td>4.54x</td>
</tr>
<tr>
<td>%C </td>
<td>30</td>
<td>150495.98</td>
<td>4.55x</td>
</tr>
<tr>
<td>%L</td>
<td>50</td>
<td>151044.66</td>
<td>4.56x</td>
</tr>
<tr>
<td>%C </td>
<td>5</td>
<td>151478.15</td>
<td>4.58x</td>
</tr>
<tr>
<td>%C </td>
<td>35</td>
<td>151516.71</td>
<td>4.58x</td>
</tr>
<tr>
<td>%M </td>
<td>45</td>
<td>152534.57</td>
<td>4.61x</td>
</tr>
<tr>
<td>%C </td>
<td>15</td>
<td>152969.01</td>
<td>4.62x</td>
</tr>
<tr>
<td>%M </td>
<td>50</td>
<td>152989.03</td>
<td>4.62x</td>
</tr>
<tr>
<td>%C </td>
<td>50</td>
<td>154476.76</td>
<td>4.67x</td>
</tr>
<tr>
<td>%F</td>
<td>40</td>
<td>155057.98</td>
<td>4.68x</td>
</tr>
<tr>
<td>%C </td>
<td>45</td>
<td>155471.11</td>
<td>4.70x</td>
</tr>
<tr>
<td>%M </td>
<td>35</td>
<td>155759.06</td>
<td>4.70x</td>
</tr>
<tr>
<td>%C </td>
<td>40</td>
<td>165737.16</td>
<td>5.01x</td>
</tr>
<tr>
<td>%l </td>
<td>10</td>
<td>170275.18</td>
<td>5.14x</td>
</tr>
<tr>
<td>%l </td>
<td>5</td>
<td>172227.11</td>
<td>5.20x</td>
</tr>
<tr>
<td>%l </td>
<td>20</td>
<td>172265.43</td>
<td>5.20x</td>
</tr>
<tr>
<td>%l </td>
<td>35</td>
<td>174530.94</td>
<td>5.27x</td>
</tr>
<tr>
<td>%l </td>
<td>50</td>
<td>175687.72</td>
<td>5.31x</td>
</tr>
<tr>
<td>%l </td>
<td>45</td>
<td>177227.30</td>
<td>5.35x</td>
</tr>
<tr>
<td>%l </td>
<td>15</td>
<td>177944.97</td>
<td>5.37x</td>
</tr>
<tr>
<td>%l </td>
<td>30</td>
<td>177987.91</td>
<td>5.38x</td>
</tr>
<tr>
<td>%l </td>
<td>25</td>
<td>181043.73</td>
<td>5.47x</td>
</tr>
<tr>
<td>%l </td>
<td>40</td>
<td>186023.07</td>
<td>5.62x</td>
</tr>
<tr>
<td>%F</td>
<td>1</td>
<td>203322.88</td>
<td>6.14x</td>
</tr>
<tr>
<td>%L</td>
<td>1</td>
<td>209034.65</td>
<td>6.31x</td>
</tr>
<tr>
<td>%C </td>
<td>1</td>
<td>218245.92</td>
<td>6.59x</td>
</tr>
<tr>
<td>%M </td>
<td>1</td>
<td>222148.81</td>
<td>6.71x</td>
</tr>
<tr>
<td>%l </td>
<td>1</td>
<td>223007.37</td>
<td>6.74x</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://javatech.org/2008/02/log4j-conversion-pattern-performance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Freemarker vs Raw Java</title>
		<link>http://javatech.org/2008/02/freemarker-vs-raw-java/</link>
		<comments>http://javatech.org/2008/02/freemarker-vs-raw-java/#comments</comments>
		<pubDate>Tue, 26 Feb 2008 07:27:31 +0000</pubDate>
		<dc:creator>deevis</dc:creator>
				<category><![CDATA[Benchmarks]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://javatech.org/?p=24</guid>
		<description><![CDATA[I&#8217;ve recently been pitting Freemarker against Raw Java of late because I was under the impression that Freemarker would blow up under load in a multi-threaded environment.  Well, it turns out that things aren&#8217;t nearly as bad as I&#8217;d thought, but it&#8217;s still significantly slower than what I&#8217;ve been calling &#8220;Raw Java&#8221;.   [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently been pitting Freemarker against Raw Java of late because I was under the impression that Freemarker would blow up under load in a multi-threaded environment.  Well, it turns out that things aren&#8217;t nearly as bad as I&#8217;d thought, but it&#8217;s still significantly slower than what I&#8217;ve been calling &#8220;Raw Java&#8221;.   Here&#8217;s the final results with a pretty graph and everything.<br />
<a href="http://javatech.org/wp-content/uploads/2008/03/freemarker_vs_raw_java_2008_03_12__02_02_am.png" title="freemarker_vs_raw_java_2008_03_12__02_02_am.png"><img src="http://javatech.org/wp-content/uploads/2008/03/freemarker_vs_raw_java_2008_03_12__02_02_am.png" alt="freemarker_vs_raw_java_2008_03_12__02_02_am.png" /></a><a href="http://javatech.org/wp-content/uploads/2008/02/freemarker_vs_raw_java_2008_02_26__12_21_am.png" title="Freemarker vs Raw Java"><br />
</a><br />
Previous test results had shown Freemarker going into the 200 times slower category, but it does actually stay in the 20 times slower category.  So, I&#8217;m not nearly as freaked out by this as I was a few weeks ago.  I still think that the example I&#8217;m using, where the FTL is more of a program than a template, that the Raw Java method is nearly as appropriate and positively 20 times faster!</p>
<h4>Freemarker vs Raw Java</h4>
<p style="font-size: smaller; font-weight: bolder">JVM Version 1.6.0_05-ea<br />
Windows XP[x86] &#8211; 2 processors<br />
4.99MB/63.56MB Memory</p>
<table border="1">
<tr>
<th>Benchmark</th>
<th>Threads</th>
<th>Avg Nanos</th>
<th>Slow Factor</th>
</tr>
<tr>
<td>Raw Java</td>
<td>50</td>
<td>1585.19</td>
<td>1.00x</td>
</tr>
<tr>
<td>Raw Java</td>
<td>30</td>
<td>1796.52</td>
<td>1.13x</td>
</tr>
<tr>
<td>Raw Java</td>
<td>20</td>
<td>1862.14</td>
<td>1.17x</td>
</tr>
<tr>
<td>Raw Java</td>
<td>10</td>
<td>1890.36</td>
<td>1.19x</td>
</tr>
<tr>
<td>Raw Java</td>
<td>60</td>
<td>1891.35</td>
<td>1.19x</td>
</tr>
<tr>
<td>Raw Java</td>
<td>40</td>
<td>1891.70</td>
<td>1.19x</td>
</tr>
<tr>
<td>Raw Java</td>
<td>1</td>
<td>2494.68</td>
<td>1.57x</td>
</tr>
<tr>
<td>Freemarker</td>
<td>10</td>
<td>26320.65</td>
<td>16.60x</td>
</tr>
<tr>
<td>Freemarker</td>
<td>20</td>
<td>27597.29</td>
<td>17.41x</td>
</tr>
<tr>
<td>Freemarker</td>
<td>30</td>
<td>28638.00</td>
<td>18.07x</td>
</tr>
<tr>
<td>Freemarker</td>
<td>40</td>
<td>29562.36</td>
<td>18.65x</td>
</tr>
<tr>
<td>Freemarker</td>
<td>50</td>
<td>30019.56</td>
<td>18.94x</td>
</tr>
<tr>
<td>Freemarker</td>
<td>60</td>
<td>31576.83</td>
<td>19.92x</td>
</tr>
<tr>
<td>Freemarker</td>
<td>1</td>
<td>34447.90</td>
<td>21.73x</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://javatech.org/2008/02/freemarker-vs-raw-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MultiThreaded Freemarker Benchmarks</title>
		<link>http://javatech.org/2008/02/multithreaded-freemarker-benchmarks/</link>
		<comments>http://javatech.org/2008/02/multithreaded-freemarker-benchmarks/#comments</comments>
		<pubDate>Fri, 22 Feb 2008 05:47:07 +0000</pubDate>
		<dc:creator>deevis</dc:creator>
				<category><![CDATA[Benchmarks]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://javatech.org/?p=23</guid>
		<description><![CDATA[I recently blogged about Freemarker performing 10-20x slower than pure Java analogues.  I got to thinking about our webapp and the fact that I wasn&#8217;t quite testing the correct scenario.  In a web environment there might be numerous threads all running Freemarker templates simultaneously.  So, I had to put the pure Java [...]]]></description>
			<content:encoded><![CDATA[<p>I recently <a href="http://javatech.org/?p=21" title="Freemarker vs Pure Java">blogged about Freemarker performing 10-20x slower</a> than pure Java analogues.  I got to thinking about our webapp and the fact that I wasn&#8217;t quite testing the correct scenario.  In a web environment there might be numerous threads all running Freemarker templates simultaneously.  So, I had to put the pure Java analogues up against the simple Freemarker template in a multithreaded test.  I ran tests for each with 10,20,40,60 and 80 threads.  The results are more impetus towards moving away from Freemarker for the most used and most basic cases ( input tags, labels, script includes ).</p>
<p>So how bad is it&#8230;drum roll&#8230;</p>
<p>Class[10] indicates the pure Java method running a 10 Thread test.  FTL[20] indicates the Freemarker test running a 20 Thread test.  And so on&#8230; Results are listed from best to worst with the avg and max results in nanoseconds.</p>
<p style="border: 1px solid ; background: #cccccc none repeat scroll 0% 50%; color: red; padding-left: 5px; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial"> Class[10]:    1000100 trials,    18046 avg, 67973245 max    1.0x<br />
Class[80]:    1000800 trials,    28960 avg, 104784259 max  1.6x<br />
Class[20]:    1000200 trials,    30387 avg, 106770756 max  1.7x<br />
Class[60]:    1000200 trials,    35917 avg, 96320112 max    2.0x<br />
Class[40]:    1000400 trials,    37220 avg, 162898182 max   2.1x<br />
FTL[10]:    1000100 trials,   293093 avg, 104114975 max  16.2x<br />
FTL[20]:    1000200 trials,   587117 avg,      158432568 max  32.5x<br />
FTL[40]:    1000400 trials,  1204641 avg,      190966244 max  66.8x<br />
FTL[60]:    1000200 trials,  1843190 avg,      284686324 max  102.1x<br />
FTL[80]:    1000800 trials,  2498693 avg,      358187778 max  138.5x</p>
<p>The last piece of info on each line is how much slower that particular test was ( on average ) than the fastest.  Notice how the pure Java tests don&#8217;t jump right into the crapper when under load.  But the FTL tests get progressively worse as the thread counts are increased.  Under an 80 thread load, not only is the pure Java way 138 times faster on average, but the FTL way has max time of 358 milliseconds vs a 104 millisecond max for pure Java.  This is a perceptible 250 millisecond difference when rendering a single button tag!</p>
<p>The case for easing up on the Freemarker templates is solidifying <img src='http://javatech.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://javatech.org/2008/02/multithreaded-freemarker-benchmarks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Freemarker Benchmarks</title>
		<link>http://javatech.org/2008/02/freemarker-benchmarks/</link>
		<comments>http://javatech.org/2008/02/freemarker-benchmarks/#comments</comments>
		<pubDate>Tue, 19 Feb 2008 06:11:46 +0000</pubDate>
		<dc:creator>deevis</dc:creator>
				<category><![CDATA[Benchmarks]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://javatech.org/?p=21</guid>
		<description><![CDATA[All of us at iCentris have currently embarked upon a torrid love affair with Freemarker templates.  I admit that I, too, have been very excited about having them around.    A freemarker template has quickly become the knee-jerk, defacto response to generating output &#8211; which is great for readability and maintainability.  [...]]]></description>
			<content:encoded><![CDATA[<p>All of us at iCentris have currently embarked upon a torrid love affair with <a href="http://freemarker.org" title="Freemarker Template Engine" target="_blank">Freemarker </a>templates.  I admit that I, too, have been very excited about having them around.    A freemarker template has quickly become the knee-jerk, defacto response to generating output &#8211; which is great for readability and maintainability.  But lately, after repeated profiling sessions with all the top offenders coming from freemarker packages, I&#8217;ve come to realize that we&#8217;re using them way too much.   And here&#8217;s why&#8230;</p>
<p>When should a template engine be used?  There seem to be two answers to this question which both carry equal weight with developers.  They are:</p>
<ol>
<li>You want to have an easily editable version of your dynamic view.  This will allow easy customization.</li>
<li>You want the representation to be easily readable to future developers.  This will keep it understandable and maintainable.</li>
</ol>
<p>Now, this might seem like a minor point to pick at.   But bear with me&#8230;</p>
<p>So, how much faster is pure java than freemarker templates?  Well, this is going to depend largely on the complexity of the template.   As an example, I&#8217;m going to pick a template of medium complexity that renders an HTML button tag in a consistent fashion.  The output will be very simple and we&#8217;ll have a lot of HTML attributes that can be set within the template.  Here&#8217;s the ftl file:</p>
<p>button.ftl</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
[source:xml]<br />
&lt;@compress single_line=true&gt;<br />
&lt;button 			&lt;#if id?exists&gt;<br />
id=&#8221;${id}&#8221;<br />
&lt;/#if&gt;</p>
<p>&lt;#if name?exists&gt;<br />
name=&#8221;${name}&#8221;<br />
&lt;/#if&gt;</p>
<p>&lt;#if value?exists&gt;<br />
value=&#8221;${value}&#8221;<br />
&lt;/#if&gt;</p>
<p>&lt;#if accesskey?exists&gt;<br />
accesskey=&#8221;${accesskey}&#8221;<br />
&lt;/#if&gt;</p>
<p>&lt;#if classname?exists&gt;<br />
class=&#8221;${classname}&#8221;<br />
&lt;/#if&gt;</p>
<p>&lt;#if style?exists&gt;<br />
style=&#8221;${style}&#8221;<br />
&lt;/#if&gt;</p>
<p>&lt;#if title?exists&gt;<br />
title=&#8221;${title}&#8221;<br />
&lt;/#if&gt;</p>
<p>&lt;#if href?exists || onclick?exists &gt;<br />
onclick=&#8221;<br />
&lt;#if href?exists&gt;document.location.href=&#8217;${href}&#8217;;&lt;/#if&gt;<br />
&lt;#if onclick?exists&gt;${onclick}&lt;/#if&gt;<br />
&#8221;<br />
&lt;/#if&gt;</p>
<p>&lt;#if ondblclick?exists&gt;<br />
ondblclick=&#8221;${ondblclick}&#8221;<br />
&lt;/#if&gt;</p>
<p>&lt;#if onmouseout?exists&gt;<br />
onmouseout=&#8221;${onmouseout}&#8221;<br />
&lt;/#if&gt;</p>
<p>&lt;#if type?exists&gt;<br />
type=&#8221;${type}&#8221;<br />
&lt;#else&gt;<br />
type=&#8221;button&#8221;<br />
&lt;/#if&gt;</p>
<p>&lt;#if disabled?exists &amp;&amp; disabled == &#8216;true&#8217; &gt;<br />
disabled=&#8221;disabled&#8221;<br />
&lt;/#if&gt;<br />
&gt;<br />
&lt;div&gt;<br />
&lt;div&gt;<br />
&lt;#if icon?exists&gt;${icon}&lt;/#if&gt;</p>
<p>&lt;span&gt;<br />
${content}<br />
&lt;/span&gt;<br />
&lt;/div&gt;<br />
&lt;/div&gt;</p>
<p>&lt;/button&gt;<br />
&lt;/@compress&gt;<br />
[/source]<br />
It outputs something along the lines of :<br />
[source:xml]<br />
&lt;button id=&#8221;buttonId&#8221; style=&#8221;buttonStyle&#8221; onclick=&#8221; alert(&#8217;hi&#8217;); &#8221; type=&#8221;button&#8221; &gt; &lt;div&gt; &lt;div&gt; &lt;img src=&#8217;pretty.jpg&#8217;&gt; &lt;span&gt; This is required &lt;/span&gt; &lt;/div&gt; &lt;/div&gt; &lt;/button&gt;<br />
[/source]</p>
<p>Now, is this a good place to use a template like the above?  The answer is Yes.  But, as with most things, only in moderation.  Or perhaps the answer is actually a definite maybe?</p>
<p>So, what can the downside be?</p>
<p>Speed.</p>
<p>Having just benchmarked this I have an unfair advantage, but the raw Java implementation that spits out the same exact templating logic presented above in button.ftl runs over 15 times faster.</p>
<p>Running 1000 trials of button.ftl (FTL) vs ButtonTemplate.java (Class) gives me the following results ( in microsecond timing ):</p>
<p>FTL 419033 micros<br />
Class 31828 micros<br />
Class is 13 times faster!</p>
<p>With only 100 trials:</p>
<p>FTL 15888 micros<br />
Class 834 micros<br />
Class is 19 times faster!</p>
<p>So, back to the moderation.  Nobody is going to notice if a couple of buttons are rendered in 1 microSecond instead of 15 microSeconds, that&#8217;s for sure.  But, if your entire page, overtime, has been rewritten to do absolutely everything using FTL, and the page ends up taking a second to load.  Well, then, a 15x speed increase would get that page out in less than a tenth of a second.</p>
<p>I ran these tests with Freemarker 2.3.10 and then again with 2.3.12 and got the same results, so the optimization they added in <a href="http://www.freemarker.org/docs/versions_2_3_11.html">2.3.11</a> doesn&#8217;t seem to affect this type of simple usage ( using maps ).</p>
<p>Here is a screenshot showing the intense framework supporting the Freemarker template engine.  Notice how the pure java class ( highlighted in blue ) just goes about its business directly.<a href="http://javatech.org/wp-content/uploads/2008/02/javavsfreemarker10.png" title="Freemarker Benchmark - 2.3.10 - Using FTL vs raw Java"><img src="http://javatech.org/wp-content/uploads/2008/02/javavsfreemarker10.png" alt="Freemarker Benchmark - 2.3.10 - Using FTL vs raw Java" /></a></p>
<p>So, back to the two reasons to use an FTL template.</p>
<ol>
<li>You want to have an easily editable version of your dynamic view.</li>
<li>You want the representation to be easily readable to future developers.</li>
</ol>
<p>Well, in regards to #1, I don&#8217;t think we really need to have an easily editable version of our &lt;button&gt; tag.  I mean, really, a button&#8217;s a button&#8217;s a button.  It might keep growing for a while, gathering more attributes and complexity over time, but I don&#8217;t think we&#8217;ll ever need to plug in a custom version for a different client.</p>
<p>As for #2, I don&#8217;t think the java code is really that much more difficult to read, and since we won&#8217;t be needing to change this (because it&#8217;s a button, for christ&#8217;s sake!) template that often, why take the speed hit here?</p>
<p>Here, btw, is the code for ButtonTemplate.java ( w/o Javabean boilerplate )<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
[source:Java]<br />
public void render( Writer out ) throws IOException {<br />
out.write( &#8220;&lt;button&#8221; );<br />
if ( id != null )        writeAttribute( out, &#8220;id&#8221;, id );<br />
if ( name != null )      writeAttribute( out, &#8220;name&#8221;, name );<br />
if ( value != null )     writeAttribute( out, &#8220;value&#8221;, value );<br />
if ( accessKey != null ) writeAttribute( out, &#8220;accesskey&#8221;, accessKey );<br />
if ( className != null ) writeAttribute( out, &#8220;class&#8221;, className );<br />
if ( style != null )     writeAttribute( out, &#8220;style&#8221;, style );<br />
if ( title != null )     writeAttribute( out, &#8220;title&#8221;, title );</p>
<p>if ( href != null || onClick != null ) {<br />
out.write( &#8221; onclick=\&#8221;" );<br />
if ( href != null ) {<br />
out.write( &#8220;document.location.href=&#8217;&#8221; );<br />
out.write(href);<br />
out.write(&#8221;&#8216;;&#8221;);<br />
}<br />
if ( onClick != null ) {<br />
out.write( onClick );<br />
}<br />
out.write( &#8220;\&#8221;" );<br />
}</p>
<p>if ( onDblClick != null )     writeAttribute( out, &#8220;ondblclick&#8221;, onDblClick );<br />
if ( onMouseOut != null )     writeAttribute( out, &#8220;onmouseout&#8221;, onMouseOut );<br />
if ( type != null )	{<br />
writeAttribute( out, &#8220;type&#8221;, type );<br />
} else {<br />
writeAttribute( out, &#8220;type&#8221;, &#8220;button&#8221; );<br />
}<br />
if ( disabled ) {<br />
writeAttribute( out, &#8220;disabled&#8221;, &#8220;disabled&#8221; );<br />
}</p>
<p>out.write( &#8221; &gt; &lt;div&gt; &lt;div&gt; &#8221; );</p>
<p>if ( icon != null ) {<br />
out.write( icon );<br />
out.write( &#8221; &#8221; );<br />
}<br />
out.write( &#8220;&lt;span&gt; &#8221; );<br />
out.write( content );<br />
out.write( &#8221; &lt;/span&gt; &lt;/div&gt; &lt;/div&gt; &lt;/button&gt;&#8221; );<br />
}</p>
<p>[/source]<br />
Now, I mentioned the torrid love affair we&#8217;re in at work.  Well, we are using  a whole lot more FTL to simply render HTML elements : inputs, labels, selects, buttons, checkboxes, creditCards, datePickers, dropDowns, addresses ( which use the previous elements ) and even style and javascript includes.   So, in conclusion, since Freemarker is the artsy smartsy way to do things and it will be used wherever and whenever possible once it takes root &#8211; I implore you to only use it where/when it is <strong>truly </strong>needed.   That is, for large views that are truly complex and for views that will be frequently customized.  For the simple cases, it&#8217;s just not worth the hit.</p>
<p>Time to go refactoring&#8230;perhaps&#8230;</p>
<p>Afterthough:::  If only the freemarker templates would compile into java bytecode, then this would probably be a nonfactor.  JSP&#8217;s can do it.  Is anyone up  to the task?</p>
]]></content:encoded>
			<wfw:commentRss>http://javatech.org/2008/02/freemarker-benchmarks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C3P0 vs DBCP &#8211; The Straight Dope</title>
		<link>http://javatech.org/2007/11/c3p0-vs-dbcp-the-straight-dope/</link>
		<comments>http://javatech.org/2007/11/c3p0-vs-dbcp-the-straight-dope/#comments</comments>
		<pubDate>Mon, 12 Nov 2007 04:18:57 +0000</pubDate>
		<dc:creator>deevis</dc:creator>
				<category><![CDATA[Benchmarks]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://javatech.org/?p=17</guid>
		<description><![CDATA[I&#8217;ve found it very difficult to find any accurate comparisons of C3P0 and DBCP.  Why should I choose C3P0 over DBCP?  When might DBCP be better?
Well, here&#8217;s a fairly in-depth overview of both with pros and cons and similarities and differences included.
The first thing to note is that if you&#8217;re not in a [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve found it very difficult to find any accurate comparisons of C3P0 and DBCP.  Why should I choose C3P0 over DBCP?  When might DBCP be better?</p>
<p>Well, here&#8217;s a fairly in-depth overview of both with pros and cons and similarities and differences included.</p>
<p>The first thing to note is that if you&#8217;re not in a multi-threaded environment, then DBCP is going to be faster than C3P0 and will also use significantly fewer connections than C3P0.  For example, using the default settings for each and sizing the pool to contain 50 connections at most, will yield results like the following single-threaded test.</p>
<p><strong>Single-threaded Benchmark &#8211; 50,000 calls to getConnection()</strong></p>
<table border="1">
<tr>
<th></th>
<th>Trials</th>
<th>MaxPoolSize</th>
<th>Connections Used</th>
<th>Seconds</th>
<th>Settings</th>
</tr>
<tr>
<th>DBCP</th>
<td>50,000</td>
<td>50</td>
<td>1</td>
<td>5.18</td>
<td>&#8212;</td>
</tr>
<tr>
<th>C3P0</th>
<td>50,000</td>
<td>50</td>
<td>50</td>
<td>6.72</td>
<td>*numHelperThreads=3</td>
</tr>
<tr>
<th>C3P0</th>
<td>50,000</td>
<td>50</td>
<td>39</td>
<td>6.6</td>
<td>numHelperThreads=4</td>
</tr>
<tr>
<th>C3P0</th>
<td>50,000</td>
<td>50</td>
<td>27</td>
<td>6.45</td>
<td>numHelperThreads=5</td>
</tr>
<tr>
<th>C3P0</th>
<td>50,000</td>
<td>50</td>
<td>30</td>
<td>6.63</td>
<td>numHelperThreads=6</td>
</tr>
</table>
<p>Suffice it to say that DBCP is obviously better suited to Single-threaded applications with high load.  Needing 50 connections in the pool to do the work where only 1 is needed is certainly not desired.  This is the case with C3P0&#8217;s default setting of &#8220;numHelperThreads=3&#8243;.  Regardless of the environment you have ( single-threaded, multi-threaded ) I would always change this setting if you forsee high load on the program.  I would always use at least &#8220;numHelperThreads=5&#8243;.  As a bit of background/explanation, C3P0 doesn&#8217;t actually make a connection available in the pool when it is checked-in.  Instead the HelperThreads will detect these and do the work to get them back in the pool.  This is great in high-load, multi-threaded environments as it avoids blocking issues.  But it inherently requires a much larger number of connections to provide the same functionality ( especially if you keep &#8220;numHelperThreads=3&#8243; ).  Also, notice that DBCP is 20% faster regardless of how we tweak numHelperThreads.</p>
<p>Score 2 points for DBCP.  2-0.</p>
<p>Next what if we run the same test with a smaller connection pool size &#8211; say of only 5 connections, and numHelperThreads=3 for C3P0?</p>
<p>The results are a bit counterintuitive ( to me at least ).  DBCP does at least manage to stay the same &#8211; very fast and reasonable ( needing just 1 connection in its pool ).  But C3P0, which I expected to take longer because it previously needed all 50 connections, but actually runs faster with a smaller pool : 6.25 seconds down from 6.7 seconds.  The lesson here is that C3P0 is slowing itself down with the HelperThreads having to manage all the extra connections to get them back in the pool.</p>
<table border="1">
<tr>
<th></th>
<th>Trials</th>
<th>MaxPoolSize</th>
<th>Connections Used</th>
<th>Seconds</th>
<th>Settings</th>
</tr>
<tr>
<th>DBCP</th>
<td>50,000</td>
<td>5</td>
<td>1</td>
<td>5.18</td>
<td>&#8212;</td>
</tr>
<tr>
<th>C3P0</th>
<td>50,000</td>
<td>5</td>
<td>5</td>
<td>6.18</td>
<td>*numHelperThreads=3</td>
</tr>
</table>
<p>Score 1 point each.  DBCP for making sense and C3P0 for speeding up.</p>
<p>3-1, DBCP in the lead.</p>
<p>Now for the good stuff &#8211; the multi-threaded tests.  I&#8217;ll be varying the number of Threads which will be running.<br />
<strong>Multi-threaded tests</strong></p>
<table border="1">
<tr>
<th></th>
<th>Threads</th>
<th>MaxPoolSize</th>
<th>Connections Used</th>
<th>Seconds</th>
<th>Settings</th>
</tr>
<tr>
<th>DBCP</th>
<td>25</td>
<td>5</td>
<td>5</td>
<td>90</td>
<td>&#8212;</td>
</tr>
<tr>
<th>DBCP</th>
<td>25</td>
<td>10</td>
<td>10</td>
<td>107</td>
<td>&#8212;</td>
</tr>
<tr>
<th>DBCP</th>
<td>25</td>
<td>25</td>
<td>25</td>
<td>167</td>
<td>&#8212;</td>
</tr>
<tr>
<th>DBCP</th>
<td>50</td>
<td>50</td>
<td>50</td>
<td>198</td>
<td>&#8212;</td>
</tr>
<tr>
<th>DBCP</th>
<td>50</td>
<td>100</td>
<td>50</td>
<td>207</td>
<td>&#8212;</td>
</tr>
<tr>
<th>C3P0</th>
<td>25</td>
<td>5</td>
<td>5</td>
<td>156</td>
<td>*numHelperThreads=3</td>
</tr>
<tr>
<th>C3P0</th>
<td>25</td>
<td>10</td>
<td>10</td>
<td>142</td>
<td>*numHelperThreads=3</td>
</tr>
<tr>
<th>C3P0</th>
<td>25</td>
<td>25</td>
<td>25</td>
<td>137</td>
<td>*numHelperThreads=3</td>
</tr>
<tr>
<th>C3P0</th>
<td>50</td>
<td>50</td>
<td>50</td>
<td>252</td>
<td>*numHelperThreads=3</td>
</tr>
<tr>
<th>C3P0</th>
<td>50</td>
<td>100</td>
<td>100</td>
<td>252</td>
<td>*numHelperThreads=3</td>
</tr>
<tr>
<th>C3P0</th>
<td>50</td>
<td>100</td>
<td>100</td>
<td>269</td>
<td>numHelperThreads=6</td>
</tr>
</table>
<p>Score yet another to DBCP.   Faster across the board on all accounts.  So, what is it about C3P0 that has everybody ( myself included ) using it and singing its praises?  Multiple threads yield multiple points again for DBCP &#8211; 2 points awarded.</p>
<p>5-1, C3P0 will need a miracle comeback at this point.</p>
<p>I know, usually Connections aren&#8217;t just checked out and run with a small SQL statement and immediately returned like the Benchmarks I&#8217;ve been running.  Maybe I need to put some delay in there to more closely mimic real world performance.  I&#8217;m going to throw a new setting in here which is a delay in milliseconds that each call to getConnection() will endure before finishing with the connection.  I&#8217;ll give it a shot with an extra 100ms of sleep time after each SQL statement is run.</p>
<p><strong>Multi-threaded &#8211; 100ms of sleep time added</strong></p>
<table border="1">
<tr>
<th></th>
<th>Threads</th>
<th>MaxPoolSize</th>
<th>Connections Used</th>
<th>Seconds</th>
<th>Settings</th>
</tr>
<tr>
<th>DBCP</th>
<td>50</td>
<td>25</td>
<td>25</td>
<td>9338</td>
<td>&#8212;</td>
</tr>
<tr>
<th>DBCP</th>
<td>50</td>
<td>10</td>
<td>10</td>
<td>20918</td>
<td>&#8212;</td>
</tr>
<tr>
<th>DBCP</th>
<td>100</td>
<td>50</td>
<td>50</td>
<td>9248</td>
<td>&#8212;</td>
</tr>
<tr>
<th>DBCP</th>
<td>0</td>
<td>50</td>
<td>50</td>
<td>0</td>
<td>&#8212;</td>
</tr>
<tr>
<th>DBCP</th>
<td>0</td>
<td>100</td>
<td>50</td>
<td>0</td>
<td>&#8212;</td>
</tr>
<tr>
<th>C3P0</th>
<td>50</td>
<td>25</td>
<td>25</td>
<td>9295</td>
<td>numHelperThreads=6</td>
</tr>
<tr>
<th>C3P0</th>
<td>50</td>
<td>10</td>
<td>10</td>
<td>20088</td>
<td>numHelperThreads=6</td>
</tr>
<tr>
<th>C3P0</th>
<td>100</td>
<td>50</td>
<td>50</td>
<td>9412</td>
<td>numHelperThreads=6</td>
</tr>
<tr>
<th>C3P0</th>
<td>0</td>
<td>50</td>
<td>50</td>
<td>0</td>
<td>*numHelperThreads=3</td>
</tr>
<tr>
<th>C3P0</th>
<td>0</td>
<td>100</td>
<td>100</td>
<td>0</td>
<td>*numHelperThreads=3</td>
</tr>
<tr>
<th>C3P0</th>
<td>0</td>
<td>100</td>
<td>100</td>
<td>0</td>
<td>numHelperThreads=6</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://javatech.org/2007/11/c3p0-vs-dbcp-the-straight-dope/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Coming soon &#8211; lots of benchmarks</title>
		<link>http://javatech.org/2007/10/coming-soon-lots-of-benchmarks/</link>
		<comments>http://javatech.org/2007/10/coming-soon-lots-of-benchmarks/#comments</comments>
		<pubDate>Sat, 27 Oct 2007 05:50:12 +0000</pubDate>
		<dc:creator>deevis</dc:creator>
				<category><![CDATA[Benchmarks]]></category>

		<guid isPermaLink="false">http://javatech.org/wordpress/?p=4</guid>
		<description><![CDATA[Webservices: Apache Axis vs XFire
Application Servers: Tomcat, Jetty, Glassfish, JBoss
Frameworks: Spring MVC, Wicket, Seam, Struts
]]></description>
			<content:encoded><![CDATA[<p>Webservices: Apache Axis vs XFire</p>
<p>Application Servers: Tomcat, Jetty, Glassfish, JBoss</p>
<p>Frameworks: Spring MVC, Wicket, Seam, Struts</p>
]]></content:encoded>
			<wfw:commentRss>http://javatech.org/2007/10/coming-soon-lots-of-benchmarks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
