#!/usr/bin/perl -w use Time::HiRes qw( time ); undef $/; $| = 0; my $file; my $start = time(); open(FILE, $ARGV[0]); $file = ; close FILE; open(FILE, ">$ARGV[1]"); print FILE $file; close FILE; my $total = time() - $start; print "$total Seconds Elapsed.\n"; #### [adamm@pepsi java_vs_perl]$ dd if=/dev/zero of=ten_meg_file.txt seek=10 count=1 bs=1M 1+0 records in 1+0 records out [adamm@pepsi java_vs_perl]$ perl -w cp.pl ten_meg_file.txt out 0.405324935913086 Seconds Elapsed. [adamm@pepsi java_vs_perl]$ perl -w cp.pl ten_meg_file.txt out 0.322497963905334 Seconds Elapsed. [adamm@pepsi java_vs_perl]$ perl -w cp.pl ten_meg_file.txt out 0.321141004562378 Seconds Elapsed. [adamm@pepsi java_vs_perl]$ perl -w cp.pl ten_meg_file.txt out 0.318119049072266 Seconds Elapsed. #### import java.io.*; public class X { public static void copy(String from, String to)throws IOException{ InputStream inFile = null; OutputStream outFile = null; try { inFile = new FileInputStream(from); outFile = new FileOutputStream(to); int length = inFile.available(); byte[] bytes = new byte[length]; inFile.read(bytes); outFile.write(bytes); } finally { inFile.close(); outFile.close(); } } public static void copyBuf(String from, String to)throws IOException{ InputStream in = null; OutputStream out = null; InputStream inFile = null; OutputStream outFile = null; try { inFile = new FileInputStream(from); in = new BufferedInputStream(inFile); outFile = new FileOutputStream(to); out = new BufferedOutputStream(outFile); int length = in.available(); byte[] bytes = new byte[length]; in.read(bytes); out.write(bytes); } finally { in.close(); out.close(); } } public static void main(String[] args) { try { long l = System.currentTimeMillis(); copy(args[0], args[1]); System.out.println("Time = "+ (System.currentTimeMillis()-l)); l = System.currentTimeMillis(); copyBuf(args[0], args[1]); System.out.println("Buf Time = "+ (System.currentTimeMillis()-l)); } catch (IOException e) { e.printStackTrace(); } } } #### [adamm@pepsi java_vs_perl]$ javac X.java [adamm@pepsi java_vs_perl]$ dd if=/dev/zero of=ten_meg_file__2.txt seek=10 count=1 bs=1M 1+0 records in 1+0 records out [adamm@pepsi java_vs_perl]$ java X ten_meg_file__2.txt out__2 Time = 1205 Buf Time = 815 [adamm@pepsi java_vs_perl]$ java X ten_meg_file__2.txt out__2 Time = 722 Buf Time = 838 [adamm@pepsi java_vs_perl]$ java X ten_meg_file__2.txt out__2 Time = 814 Buf Time = 779