Hello
I'm evaluating B4A for a word search game I'm making. I have a list of 170,000 words in a text file. I've made the file compatible for reading with ReadMap, like below - the result is, loading & searching for words is fine (searching is in fact extremely quick).
However the ReadMap time takes about 4 seconds on my device (release mode), which is not bad, but I was hoping to improve on that.
So I tried 2 other approaches:
(1) convert the text file to a SQLite file, and work with that to search for words, and
(2) use ReadMap to initially create the populated Map, and then use WriteObject to store a binary version, and upon next app start, use ReadObject to populate the Map (instead of reading the text file, hoping reading an object from binary is faster than simply using ReadMap from a text file).
As for results, I've found for (1) there's basically no load time of course, but the time to find a word is around 300 ms (using select), which is much longer than a few ms (or less) using ContainsKey. For (2), I've found that WriteObject & ReadObject takes far too long (around 4 & 30 s respectively).
So simply using ReadMap alone is the best (fastest) but I wonder whether there's a faster way. Ideally I'd like to have the Map be available ASAP (immediately or better than 4 seconds).
I've read about WriteB4XObject & ReadB4XObject but it seems it's not available in the trial (and/or it's available in v2 of the RandomAccessFile library which is not available to trial users). From reading the forum, it seems these functions are faster than WriteObject & ReadObject.
Can anyone who has used WriteB4XObject & ReadB4XObject compare the performance to WriteObject & ReadObject? Alternatively is there a better/faster way to load/setup a Map to avoid a loading time for the user? Ideally, I'd like the best approach be cross-platform, so I can use the same method on B4I.
Thanks.
I'm evaluating B4A for a word search game I'm making. I have a list of 170,000 words in a text file. I've made the file compatible for reading with ReadMap, like below - the result is, loading & searching for words is fine (searching is in fact extremely quick).
B4X:
Dim m As Map
m = File.ReadMap(File.DirAssets, "words.txt")
However the ReadMap time takes about 4 seconds on my device (release mode), which is not bad, but I was hoping to improve on that.
So I tried 2 other approaches:
(1) convert the text file to a SQLite file, and work with that to search for words, and
(2) use ReadMap to initially create the populated Map, and then use WriteObject to store a binary version, and upon next app start, use ReadObject to populate the Map (instead of reading the text file, hoping reading an object from binary is faster than simply using ReadMap from a text file).
As for results, I've found for (1) there's basically no load time of course, but the time to find a word is around 300 ms (using select), which is much longer than a few ms (or less) using ContainsKey. For (2), I've found that WriteObject & ReadObject takes far too long (around 4 & 30 s respectively).
So simply using ReadMap alone is the best (fastest) but I wonder whether there's a faster way. Ideally I'd like to have the Map be available ASAP (immediately or better than 4 seconds).
I've read about WriteB4XObject & ReadB4XObject but it seems it's not available in the trial (and/or it's available in v2 of the RandomAccessFile library which is not available to trial users). From reading the forum, it seems these functions are faster than WriteObject & ReadObject.
Can anyone who has used WriteB4XObject & ReadB4XObject compare the performance to WriteObject & ReadObject? Alternatively is there a better/faster way to load/setup a Map to avoid a loading time for the user? Ideally, I'd like the best approach be cross-platform, so I can use the same method on B4I.
Thanks.