> 2) Between each test, I flush the database so that each test has a clean
>    data set to work this. This looks like:
> 
>         for (Alias<?> a : Copy.reverse(AliasRegistry.getAliasesSorted())) {
>             Jdbc.update(Registry.getDataSource(), "DELETE FROM {}", 
> Wrap.quotes(a.getTableName()));
>             if (a.isRootClass()) {
>                 Jdbc.update(Registry.getDataSource(), "ALTER SEQUENCE {} 
> RESTART WITH 1 INCREMENT BY 1;", a.getTableName() + "_id_seq");
>             }
>         }

I replaced these ~2,500 jdbc Statements this was doing with:

        Connection c = Registry.getDataSource().getConnection();
        Session s = (Session) ((JdbcConnection) c).getSession();
        Schema pub = s.getDatabase().getSchema("PUBLIC");
        try {
            for (Alias<?> a : Copy.reverse(AliasRegistry.getAliasesSorted())) {
                Table t = pub.getTableOrView(s, a.getTableName());
                t.truncate(s);
                if (a.isRootClass()) {
                    Sequence seq = pub.getSequence((a.getTableName() + 
"_id_seq").toUpperCase());
                    seq.setStartValue(1);
                }
            }
        } finally {
            c.close();
        }

Which I cast the connection to the H2-specific type and mess
around with Table and Sequence.

This removed ~29% of the testing runtime--according to the profiler; the
wall clock time saved was maybe half that. And now the t.truncate and
seq.setStartValue calls are so fast the profiler (YourKit 8) registers
them as literally "0ms" over 1,298 invocations and doesn't even show
them in the condensed view.

Pretty slick--nothing I could do with postgres. 

---

This does make me curious about YourKit's precision--obviously they
must be taking /some/ amount of time, however small that might be.

Interesting, using hrtlib, truncate takes ~0.004ms each call. Invoked
1200 times, that is 4.8ms. Which is very fast. But somewhat odd that
YourKit does not register the aggregate 4.8ms. The 0.004ms must be
under its threshold and so it just forgets about it, even after a
long time it starts adding up.

- Stephen


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to