For a new project, we have a very simple data storage need, against which we will never run queries. So, I was evaluating the performance of file systems versus databases. Wrote 2 very crude test cases:

Database:

  public static void testDatabse() throws ClassNotFoundException, SQLException {
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost/moo", "foo", "bar");
    PreparedStatement statement = con.prepareStatement("INSERT INTO FOO (BAR) VALUES(?)");

    long time1 = System.currentTimeMillis();
    for (int i = 0; i & lt; limit
    ;
    i++){
      statement.setString(1, testString);
      statement.executeUpdate();
    }
    long time2 = System.currentTimeMillis();
    System.out.println("DB time:" + (time2 - time1));

  }

File system:

  public static void testFile() throws IOException {
    BufferedWriter out = new BufferedWriter(new FileWriter("goo"));

    long time1 = System.currentTimeMillis();
    for (int i = 0; i & lt; limit
    ;
    i++){
      out.write(testString);
    }
    long time2 = System.currentTimeMillis();

    System.out.println("FS time:" + (time2 - time1));

    out.close();
  }

The results were pretty interesting:

For the simple insert that we were doing, file system won as predicated. On my AMD TURION Dual Core laptop, running windows XP Professional, got the following insert times.

DB time:219
FS time:0

We were using MyISAM as the data storage engine. If we use InnoDB, DB time shoots up much much higher.

Advertisements