Πέμπτη, 16 Οκτωβρίου 2008

Using Streams in Java

If you got confused by the number of streams in Java, check this out:

Using Java Streams: http://docs.rinet.ru/WebJPP/ch13.htm

Input and Output Streams: http://www.iam.ubc.ca/guides/javatut/java/io/index.html

Basic I/O: http://java.sun.com/docs/books/tutorial/essential/io/

Very very fast:

* Byte Streams handle I/O of raw binary data.
* Character Streams handle I/O of character data, automatically handling translation to and from the local character set.
* Buffered Streams optimize input and output by reducing the number of calls to the native API.
* Scanning and Formatting allows a program to read and write formatted text.
* I/O from the Command Line describes the Standard Streams and the Console object.
* Data Streams handle binary I/O of primitive data type and String values.
* Object Streams handle binary I/O of objects.

Ventrix's Code Folds

Ventrix's Code FoldsExplicit code

Δευτέρα, 6 Οκτωβρίου 2008

Calculate the execution time

//variables
private long start;
private long end;

//Put this before the main code
start = System.currentTimeMillis();

//Main code here

//Put this at the end of the code
end = System.currentTimeMillis();

System.out.println("Completed in +"+(end-start)+"ms");

Running a threadless application on a Intel Core2 CPU

My processor:


cat /proc/cpuinfo

ventrix@bytemobile:~$ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 15
model name : Intel(R) Core(TM)2 CPU 6300 @ 1.86GHz
stepping : 6
cpu MHz : 1875.766
cache size : 2048 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 2



I created an application to test if a number is prime or not. It isn't very special, except the fact that you can check REALLY big numbers...

The result is this:


As you can see with htop, only one of the cores is executing the application.
Also, if you take a careful look at the xfce's cpu meter, the total use of the CPU counts a 50% percent.

After 25 minutes I guess 170141183460469231731687303715884105727 IS a big number to test:)
[BTW 170141183460469231731687303715884105727 is a prime, according to http://en.wikipedia.org/wiki/List_of_prime_numbers)