Meaningless Drivel is fun!
The moose likes Beginning Java and the fly likes Timing Performance of a Sequential Search Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Timing Performance of a Sequential Search" Watch "Timing Performance of a Sequential Search" New topic

Timing Performance of a Sequential Search

Neil Forrest

Joined: Apr 03, 2005
Posts: 13
I'm new to Java. My mission is to implement a sequential search and time the performance with an array size=10^i, i=1,2,3,4,5,6. The command line has to take 2 arguments: size and number of searches. My code is below. Any suggestions in making this mess actually work?

[added code tags - Ilja]
[ April 04, 2005: Message edited by: Ilja Preuss ]
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
So what isn't working? Does the above code compile? If not, what are the errors? If it does compile, how does the behavior differ from what you expect?

If you can post some details about the exact problem, we will be more than happy to help. Also, this will help you analyze the problem for yourself so you might not need our help as much.

As a hint, check to see if your program create a different size array each time.


Java API Documentation
The Java Tutorial
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Hi Neil,

Welcome to JavaRanch!

To what Layne writes, I'll add the tidbit that Java doesn't have an exponent operator. To raise a number to a power, you can use the static pow() method in the java.lang.Math class:

size = (int) Math.pow(10, i);

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: Timing Performance of a Sequential Search
jQuery in Action, 3rd edition