<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: performance code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 26 Jul 2008 13:04:01 GMT</pubDate>
    <description>DZone Snippets: performance code</description>
    <item>
      <title>Speeding up Java I/O - Read method</title>
      <link>http://snippets.dzone.com/posts/show/5510</link>
      <description>The following example counts the number of newline bytes ('\n') in a file. It simply uses the read method on a FileInputStream: &lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt; import java.io.*;&lt;br /&gt;  &lt;br /&gt;  public class intro1 {&lt;br /&gt;    public static void main(String args[]) {&lt;br /&gt;      if (args.length != 1) {&lt;br /&gt;        System.err.println("missing filename");&lt;br /&gt;        System.exit(1);&lt;br /&gt;      }&lt;br /&gt;      try {&lt;br /&gt;        FileInputStream fis =&lt;br /&gt;            new FileInputStream(args[0]);&lt;br /&gt;        int cnt = 0;&lt;br /&gt;        int b;&lt;br /&gt;        while ((b = fis.read()) != -1) {&lt;br /&gt;          if (b == '\n')&lt;br /&gt;            cnt++;&lt;br /&gt;        }&lt;br /&gt;        fis.close();&lt;br /&gt;        System.out.println(cnt);&lt;br /&gt;      }&lt;br /&gt;      catch (IOException e) {&lt;br /&gt;        System.err.println(e);&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Subject to Sun's &lt;a href="http://developers.sun.com/license/berkeley_license.html"&gt;Code Sample License&lt;/a&gt;</description>
      <pubDate>Sat, 17 May 2008 14:49:13 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5510</guid>
      <author>rick (Rick Ross)</author>
    </item>
    <item>
      <title>FInd slow actions in a Rails app</title>
      <link>http://snippets.dzone.com/posts/show/4440</link>
      <description>&lt;code&gt;&lt;br /&gt;# Show a list of actions sorted by time taken. Useful for finding slow actions.&lt;br /&gt;cat log/development.log | awk '/Completed/ { print "[" $3 "] - " $0 }' | sort -nr&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 21 Aug 2007 21:08:20 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4440</guid>
      <author>sikelianos (Zeke Sikelianos)</author>
    </item>
    <item>
      <title>StopWatch - Why is my app so slow ???</title>
      <link>http://snippets.dzone.com/posts/show/3474</link>
      <description>StopWatch is a small class allowing to manage multiple concurrent stopwatches to measure time elapsed between two calls. Nothing is done while time is rolling (no thread, no loop), it only stores and compares timestamps.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import java.util.Hashtable;&lt;br /&gt;&lt;br /&gt;public class StopWatch {&lt;br /&gt;    private static final Hashtable startTime = new Hashtable();&lt;br /&gt;    &lt;br /&gt;    public static void start(String id){&lt;br /&gt;        startTime.put(id,new Long(System.currentTimeMillis()));&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public static long stop(String id){&lt;br /&gt;        return System.currentTimeMillis() - ((Long)startTime.remove(id)).longValue();&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Example of use :&lt;br /&gt;&lt;code&gt;&lt;br /&gt;public main(String[] args) {&lt;br /&gt;    // Start a global stopwatch&lt;br /&gt;    StopWatch.start("GLOBAL");&lt;br /&gt;&lt;br /&gt;    // evaluate time used by task 1&lt;br /&gt;    StopWatch.start("TASK1");&lt;br /&gt;    executeTask1();&lt;br /&gt;    System.out.println("Time elapsed for task 1 : " + StopWatch.stop("TASK1") + "ms";&lt;br /&gt;&lt;br /&gt;    // evaluate time used by task 2&lt;br /&gt;    StopWatch.start("TASK2");&lt;br /&gt;    executeTask2();&lt;br /&gt;    System.out.println("Time elapsed for task 2 : " + StopWatch.stop("TASK2") + "ms";&lt;br /&gt;&lt;br /&gt;    // Display time elapsed for full processing&lt;br /&gt;    System.out.println("Total processing time : " + StopWatch.stop("GLOBAL") + "ms";&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 07 Feb 2007 21:51:22 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3474</guid>
      <author>nivek (Kevin Gaudin)</author>
    </item>
    <item>
      <title>Switch Oracle CLOB to VARCHAR2</title>
      <link>http://snippets.dzone.com/posts/show/3022</link>
      <description>This rake task creates a database script to change all Oracle CLOB columns to VARCHAR2 columns.&lt;br /&gt;&lt;br /&gt;Changing Oracle CLOBs to VARCHAR2s can result in a huge performance increase, especially if the database and app servers are not close together on the network.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;namespace :db do&lt;br /&gt;  task :fix_clobs =&gt; [:environment] do |t|&lt;br /&gt;    @outfile = File.expand_path(File.join(RAILS_ROOT,"db","fix_clobs.sql"))&lt;br /&gt;  &lt;br /&gt;    File.open(@outfile, "w") do |file|&lt;br /&gt;      ActiveRecord::Base.connection.tables.each do |table_name|&lt;br /&gt;        begin&lt;br /&gt;          model = eval(table_name.classify)&lt;br /&gt;          model.columns.each do |column|&lt;br /&gt;            if column.sql_type == "CLOB"&lt;br /&gt;              file.write("ALTER TABLE #{table_name} ADD #{column.name}_temp VARCHAR2(4000);\n")&lt;br /&gt;              file.write("UPDATE #{table_name} SET #{column.name}_temp = #{column.name};\n")&lt;br /&gt;              file.write("COMMIT;\n")&lt;br /&gt;              file.write("ALTER TABLE #{table_name} DROP COLUMN #{column.name};\n")&lt;br /&gt;              file.write("ALTER TABLE #{table_name} RENAME COLUMN #{column.name}_temp TO #{column.name};\n")&lt;br /&gt;              file.write("\n")&lt;br /&gt;            end&lt;br /&gt;          end&lt;br /&gt;         rescue =&gt; ex&lt;br /&gt;           puts "Failed for #{table_name} with #{ex.class}"&lt;br /&gt;         end&lt;br /&gt;      end&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 20 Nov 2006 08:23:21 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3022</guid>
      <author>dcmanges (Dan Manges)</author>
    </item>
    <item>
      <title>High-performance Ruby: faster Symbol.to_s</title>
      <link>http://snippets.dzone.com/posts/show/2423</link>
      <description>Here's something that I found useful for shaving a few microseconds off. The performance gain ranges between 10% and 35%! YMMV.&lt;br /&gt;&lt;br /&gt;Note: updated with suggestion by trans.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;class Symbol&lt;br /&gt;  def to_s&lt;br /&gt;    @str_rep || (@str_rep = id2name.freeze)&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 15 Aug 2006 11:22:50 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2423</guid>
      <author>ciconia (Sharon Rosner)</author>
    </item>
    <item>
      <title>Analyse a MySQL Table for Inefficiencies</title>
      <link>http://snippets.dzone.com/posts/show/1447</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;SELECT * FROM tags PROCEDURE ANALYSE()&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 09 Feb 2006 22:56:32 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1447</guid>
      <author>offspinner ()</author>
    </item>
    <item>
      <title>Analyse a MySQL Query for inefficiencies</title>
      <link>http://snippets.dzone.com/posts/show/1446</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;EXPLAIN SELECT t2.dbid, t2.tag, COUNT(t2.dbid) * 20 AS match_count&lt;br /&gt;FROM tags AS t1, tags AS t2&lt;br /&gt;WHERE t1.dbid = '105318'&lt;br /&gt;AND t2.tag = t1.tag&lt;br /&gt;AND t1.dbid != t2.dbid&lt;br /&gt;GROUP BY t2.dbid&lt;br /&gt;ORDER BY match_count;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 09 Feb 2006 22:40:35 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1446</guid>
      <author>offspinner ()</author>
    </item>
    <item>
      <title>Setup for Performance Testing: Clear cache, buffers (MSSQL)</title>
      <link>http://snippets.dzone.com/posts/show/951</link>
      <description>For Microsoft SQL (MSSQL).&lt;br /&gt;Use this to clear the cache and buffers to ensure comparison are accurate.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;dbcc freeproccache&lt;br /&gt;go&lt;br /&gt;dbcc dropcleanbuffers&lt;br /&gt;go&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 08 Dec 2005 03:33:32 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/951</guid>
      <author>MattScilipoti (Matt Scilipoti)</author>
    </item>
  </channel>
</rss>
