<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"><channel><title>RSS feed for InstantSpot site EdomGroup Blog</title><link>http://edomgroup.instantspot.com</link><description>ColdFusion, Java, Computer Science, and the musings of inspired developers...</description><language>en-us</language><copyright>This work is Copyright &#xA9; 2009 by EdomGroup Blog</copyright><generator>RSSVille ColdFusion FeedMaker, version 1.0</generator><pubDate>Sat, 21 Nov 2009 12:53:30 GMT</pubDate><item><title>Color Space Generator</title><link>http://edomgroup.instantspot.com/blog/2006/10/12/Color-Space-Generator</link><description>Part of the work I&amp;#39;ve been doing for my thesis involves generating  color images from indexed files. This is the same principle as any  indexed image format (like GIF) where each pixel is a number which maps  to a table of red, green, blue values. At the time I knew how to get  the basic 256 colors from the color wheel. The problem was the fact  that my indexed image needed over 100,000 different colors. Of course  generating 100K colors is one thing, making an image that uses so many  colors look good is another. So after a day of digesting color theory  websites I finally understood the concept of a color space, color  models, gamuts and enough on how they go together to make a Java class  that lets me generate a color space where the colors work together.  I&amp;#39;ve uploaded a zip of the class file &lt;a href=&quot;http://www.edomgroup.com/blog/enclosures/ColorSpaceGenerator.zip&quot;&gt;here&lt;/a&gt;  for anyone who can find some use for it. At the time I was tempted to  add an alpha channel which would cause a gradient around color values,  maybe later. To use the class simply call the generate method, the  arguments are: the starting color offset (0 to 1785), next is the  number of colors to generate, and finally the number of colors to skip  in between.   &lt;p&gt;  Enjoy.      &lt;/p&gt;  &lt;p&gt;  The pure color values are on the following offsets:    &lt;/p&gt;      &lt;table border=&quot;0&quot; width=&quot;236&quot; height=&quot;170&quot;&gt;   &lt;thead&gt;        &lt;th&gt;Offset&lt;/th&gt;    &lt;th&gt;R&lt;/th&gt;&lt;th&gt;G&lt;/th&gt;&lt;th&gt;B&lt;/th&gt;     &lt;/thead&gt;        &lt;tbody&gt;            &lt;tr&gt;     &lt;td&gt;0   &lt;/td&gt;     &lt;td&gt;255&lt;/td&gt;     &lt;td&gt;0  &lt;/td&gt;     &lt;td&gt;0  &lt;/td&gt;    &lt;/tr&gt;            &lt;tr&gt;     &lt;td&gt;255 &lt;/td&gt;     &lt;td&gt;255&lt;/td&gt;     &lt;td&gt;255&lt;/td&gt;     &lt;td&gt;0  &lt;/td&gt;    &lt;/tr&gt;            &lt;tr&gt;     &lt;td&gt;510 &lt;/td&gt;     &lt;td&gt;0  &lt;/td&gt;     &lt;td&gt;255&lt;/td&gt;     &lt;td&gt;0  &lt;/td&gt;    &lt;/tr&gt;            &lt;tr&gt;     &lt;td&gt;765 &lt;/td&gt;     &lt;td&gt;0  &lt;/td&gt;     &lt;td&gt;255&lt;/td&gt;     &lt;td&gt;255&lt;/td&gt;    &lt;/tr&gt;            &lt;tr&gt;     &lt;td&gt;1020&lt;/td&gt;     &lt;td&gt;255&lt;/td&gt;     &lt;td&gt;255&lt;/td&gt;     &lt;td&gt;255&lt;/td&gt;    &lt;/tr&gt;            &lt;tr&gt;     &lt;td&gt;1275&lt;/td&gt;     &lt;td&gt;0  &lt;/td&gt;     &lt;td&gt;255&lt;/td&gt;     &lt;td&gt;255&lt;/td&gt;    &lt;/tr&gt;            &lt;tr&gt;     &lt;td&gt;1530&lt;/td&gt;     &lt;td&gt;0  &lt;/td&gt;     &lt;td&gt;255&lt;/td&gt;     &lt;td&gt;0  &lt;/td&gt;    &lt;/tr&gt;            &lt;tr&gt;     &lt;td&gt;1785&lt;/td&gt;     &lt;td&gt;0  &lt;/td&gt;     &lt;td&gt;0  &lt;/td&gt;     &lt;td&gt;0&lt;/td&gt;    &lt;/tr&gt;   &lt;/tbody&gt;  &lt;/table&gt;  </description><pubDate>Thu, 12 Oct 2006 12:07:19 GMT</pubDate><guid>http://edomgroup.instantspot.com/blog/2006/10/12/Color-Space-Generator</guid><category>Design</category></item><item><title>Java performance analysis - a real life example</title><link>http://edomgroup.instantspot.com/blog/2006/06/01/Java-performance-analysis--a-real-life-example</link><description>For my thesis I&amp;#39;m writing a Java program that parses two text files  (representing satellite images) and performs some analysis on them. The  two files are 128 MB and each was taking ~33 seconds to parse. The  analysis takes only a fraction of that time, then the results are  written back to an output file.   &lt;p&gt;  Thinking this was very slow, since the files should be pretty much  sequential access off the disk and the read-ahead-buffer would have  cached the next block, I decided to dig a little. I rewrote the parsing  algorithm in C since it&amp;#39;s easier to manage the low-level IO. I used the  file stream functions (fopen,fread,fclose) provided by stdio. When I ran the program it took ~10 seconds.      &lt;/p&gt;  &lt;p&gt;  This was insane. Java does have more overhead due to its garbage  collection, HotSpot optimizer, and object memory management but it  should not be a magnitude of 3x slower. After a few minutes looking at  the Java implementation I realized I had forgotten to instantiate a BufferedReader. I immediately jumped to the documentation and there it was, each call to the read method of the FileReader blocks until data is available. If no BufferedReader  is supplied this means a context switch for each call. No wonder Java  was taking so long. Adding the buffering I reran the algorithm and wow,  13 seconds. Not to bad for a &amp;ldquo;boated&amp;rdquo; language.   &lt;/p&gt;  &lt;p&gt;  Figuring I had more places in my program which could be optimized I  began looking. The first place I went was to one of the main methods,  the one which did the analysis on each image. The logic was pretty  simple, find the next pattern in the given image, see if it exists in a  lookup table, if so update its statistics or create a new key and add  it as a new entry. The data structure I was using for the lookup table  was a simple HashMap  object. When writing that section of the program I was still relatively  new to the Java language and just went with what I&amp;#39;d used in other  languages, an associative array.   &lt;/p&gt;  &lt;p&gt;  I did a little analysis with some System.out.println  statements and found that on average there was a 14,000 : 15 ratio  between reads and writes on the lookup table. Knowing this ratio was  pretty stable (I wasn&amp;#39;t going to get anywhere near 50% writes) I  decided a better data structure would be something with read time of  O(n) or less, instead of O(h(k)) where h(k) was the hash function on  the key. This meant an array would be best, but I didn&amp;#39;t want the  hassle of managing the size of the array as new patterns where found.  Java had to have something for this. After a little searching I found java.util.concurrent.CopyOnWriteArrayList. This was exactly what I needed. After a little tweaking the new code ran in 1/3 the time.      &lt;/p&gt;  &lt;p&gt;  After this I wrote some small timed programs to examine the running time of the HashMap data structure and the CopyOnWriteArrayList. What I found was as the mutations  approached 25% the CopyOnWriteArrayList&amp;#39;s  performance slowed at an exponential rate. Finally, I couldn&amp;#39;t evaluate  the performance because the tests were taking too long. On the other  hand, the HashMap data structure had a fairly constant performance time irrelevant on the read/write ratio.   &lt;/p&gt;  </description><pubDate>Fri, 02 Jun 2006 03:43:25 GMT</pubDate><guid>http://edomgroup.instantspot.com/blog/2006/06/01/Java-performance-analysis--a-real-life-example</guid><category>Java</category></item></channel></rss>