Skip to content

Instantly share code, notes, and snippets.

@nevercast
Created January 27, 2012 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nevercast/1688063 to your computer and use it in GitHub Desktop.
Save nevercast/1688063 to your computer and use it in GitHub Desktop.
Test HDD speeds
import java.io.File;
public class test {
/* Tests:
* 1. Time to create 2000 files
* 2. Time to list them
* 3. Time to delete all of them
* 4. Time to create 2000 files of 1kB each
* 5. Time to list them
* 6. Time to delete all of them
*/
public static final int FILE_COUNT = 2000;
public static final int BYTE_COUNT = 1*1024;
public static final File DIRECTORY = new File(".");
public static long time_t1,time_t2,time_t3,time_t4,time_t5,time_t6, start;
public static File[] filenames = new File[FILE_COUNT];
public static byte[] buffer = new byte[BYTE_COUNT];
public static void main(String[] args){
System.out.println("Test HDD IO speeds - NeverCast");
System.out.println(FILE_COUNT + " files");
System.out.println(BYTE_COUNT + " bytes");
for(int i = 0; i < FILE_COUNT; i++) {
filenames[i] = new File("f" + i + ".test");
}
for(int i = 0; i < BYTE_COUNT; i++){
buffer[i] = (byte)(i % 127);
}
try{
test1();
test2();
test3();
test4();
test5();
test6();
}catch(java.io.IOException e){
e.printStackTrace();
}
printTests();
}
public static void test1() throws java.io.IOException {
start = System.nanoTime();
for(File file : filenames){
file.createNewFile();
}
time_t1 = System.nanoTime() - start;
}
public static void test2() throws java.io.IOException {
start = System.nanoTime();
DIRECTORY.list();
time_t2 = System.nanoTime() - start;
}
public static void test3() throws java.io.IOException {
start = System.nanoTime();
for(File file : filenames){
file.delete();
}
time_t3 = System.nanoTime() - start;
}
public static void test4() throws java.io.IOException {
java.io.FileOutputStream fos;
start = System.nanoTime();
for(File file : filenames) {
fos = new java.io.FileOutputStream(file);
fos.write(buffer);
fos.close();
}
time_t4 = System.nanoTime() - start;
}
public static void test5() throws java.io.IOException {
start = System.nanoTime();
DIRECTORY.list();
time_t5 = System.nanoTime() - start;
}
public static void test6() throws java.io.IOException {
start = System.nanoTime();
for(File file : filenames){
file.delete();
}
time_t6 = System.nanoTime() - start;
}
public static void printTests(){
System.out.println("Test 1 [Create Empty Files]" + time_t1 /1000000f + "ms");
System.out.println("Test 2 [List Empty Files]" + time_t2 /1000000f + "ms");
System.out.println("Test 3 [Delete Empty Files]" + time_t3 /1000000f + "ms");
System.out.println("Test 4 [Create data Files]" + time_t4 /1000000f + "ms");
System.out.println("Test 5 [List data Files]" + time_t5 /1000000f + "ms");
System.out.println("Test 6 [Delete data Files]" + time_t6 /1000000f + "ms");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment