analogy project
Aug. 15th, 2007 03:11 pmToday I implemented caching for the NGramDatabase class, and made lots of little improvements to my code.
I'm pleased about having written code that flattens the HashMap object into a file (the secret is to use an ObjectOutputStream).
The results of caching were encouraging. For ~30000 queries (40 * 6 * 128), using a complete cache of 849kb, my program runs in 17 seconds instead of 40 minutes.
Lesson of the day: when using HashMap< K, V >, make sure K is a literal (String is close enough). It would have been more natural to use string arrays, but the problem is that each time that you query, the array will be a different object. As a result, the HashMap (i.e. 'cache') will keep growing, and will never get used.
To Do:
* enable queries with wildcards: will first need to refactor Andy's code, before modifying the SQL query.
I'm pleased about having written code that flattens the HashMap object into a file (the secret is to use an ObjectOutputStream).
The results of caching were encouraging. For ~30000 queries (40 * 6 * 128), using a complete cache of 849kb, my program runs in 17 seconds instead of 40 minutes.
Lesson of the day: when using HashMap< K, V >, make sure K is a literal (String is close enough). It would have been more natural to use string arrays, but the problem is that each time that you query, the array will be a different object. As a result, the HashMap (i.e. 'cache') will keep growing, and will never get used.
To Do:
* enable queries with wildcards: will first need to refactor Andy's code, before modifying the SQL query.