Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML


 

Search Host

Monthly Fee($)
Disk Space (MB)
Register With us for Newsletter!
Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Have tutorials?
Add your tutorial to our Java Resource and get tons of hits.

We offer free hosting for your tutorials. and exposure for thousands of readers. drop a mail
roseindia_net@yahoo.com
 
   

Tutorials

Java Server Pages

JAXB

Java Beans

JDBC

MySQL

Java Servlets

Struts

Bioinformatics

Java Code Examples

Interview Questions

 
Join For Newsletter

Powered by groups.yahoo.com
Visit Group! Post Questions!

Web Promotion

Web Submission

Submit Sites

Manual Submission?

Web Promotion Guide

Hosting Companies

Web Hosting Guide

Web Hosting

Linux

Beginner Guide to Linux Server

Frameworks

Persistence Framework

Web Frameworks

Free EAI Tools

Web Servers

Aspect Oriented Programming

Free Proxy Servers

Softwares

Adware & Spyware Remover

Open Source Softwares

Multi-Dimensional Arrays - Creation Performance

       

2003-05-18 The Java Specialists' Newsletter [Issue 070b] - Multi-Dimensional Arrays - Creation Performance

Author: Dr. Heinz M. Kabutz

If you are reading this, and have not subscribed, please consider doing it now by going to our subscribe page. You can subscribe either via email or RSS.


One of our subscribers, Martin Schulte from Germany, sent me a correction for yesterday's newsletter, and I do not want to take too long before publishing it, since it is rather significant.

Martin discovered that the biggest difference in performance is the creation of the multi-dimensional arrays. Mark Grand also thought I should point out that there are no multi-dimensional arrays in Java, only arrays of arrays. This is the reason why we have a difference in performance when we create these arrays of arrays.

The difference in creation times can be seen in this small test example, I have left out the syntax highlighting to see your reaction ;-)

public class CreationTimes {
  private final static int ITERATIONS = 1000000;
  private final static int NUM_BINS = 20;
  private final static int THE_OTHER_DIM = 4;

  public static void main(String[] args) {
    testMultiArray();
    testMultiArray2();
    testSingleArray();
  }

  private static void testMultiArray() {
    long time = -System.currentTimeMillis();

    for (int repeat = 0; repeat < ITERATIONS; repeat++) {
      int[][] aTwoDim = new int[NUM_BINS][THE_OTHER_DIM];
    }

    time += System.currentTimeMillis();
    System.out.println("Time Elapsed for [][" + THE_OTHER_DIM + "] - " +
                       time);
  }

  private static void testMultiArray2() {
    long time = -System.currentTimeMillis();

    for (int repeat = 0; repeat < ITERATIONS; repeat++) {
      int[][] aTwoDim = new int[THE_OTHER_DIM][NUM_BINS];
    }

    time += System.currentTimeMillis();
    System.out.println("Time Elapsed for [" + THE_OTHER_DIM + "][] - " +
                       time);
  }

  private static void testSingleArray() {
    long time = -System.currentTimeMillis();

    for (int repeat = 0; repeat < ITERATIONS; repeat++) {
      int[] aOneDim = new int[NUM_BINS * THE_OTHER_DIM];
    }

    time += System.currentTimeMillis();
    System.out.println("Time Elapsed for [] - " + time);
  }
}

The result of running this code is:

Time Elapsed for [][4] - 9653
Time Elapsed for [4][] - 2394
Time Elapsed for [] - 671

On another note, I will be joining an elite group of authors on Bill Venners' Weblogs. The others on the list are really quite famous, so I am there to bring some balance :-) Check out the artima website on http://www.artima.com, I should be there within a week or so. I plan to use that forum as a supplement to my newsletter, and it will give you an opportunity to chat back publicly as well.

Kind regards

Heinz


This material from The Java(tm) Specialists' Newsletter by Maximum Solutions (South Africa). Please contact Maximum Solutions for more information.

       

Useful Links
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright 2007. All rights reserved.