Android Question What is wrong with this time measurement?

RB Smissaert

Well-Known Member
Licensed User
Longtime User
B4X:
Dim lStart As Long
Dim lEnd As Long

lStart = DateTime.Now
CursorSQLEdit = SQL1.ExecQuery(strSQL)
lEnd = DateTime.Now - lStart

Problem is lEnd just gives me the wrong number of millisecond, way too less.
Even when I put a messagbox just before the line starting with lEnd and taking seconds
to dismiss it will give me some 25 milliseconds only.

RBS
 

LucaMs

Expert
Licensed User
Longtime User
I think you need to use the: ExecQueryAsync method to allow the query to finish. See link for details:
https://www.b4x.com/android/forum/threads/b4x-sql-with-wait-for.79532/#content
No, you gave him a link that teaches you to use the "wait for".

The query executed synchronously should do what @RB Smissaert wants; and might take few ms.

The messagebox blocks the thread (this is the reason why it is recommended to use asynchronous dialogs and for those 25 ms, I think)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Problem is lEnd just gives me the wrong number of millisecond, way too less.
This is one of the unqualified help-request i saw in this forum.

Help us help you!!! Upload a small project which shows the issue.

We do not know what result you got, we do not know what sql query you are using and what database is behin the query.

If the aboce code returns 25 ms then i guess it is OK. Querying the Database can be fast.

Help us giving us more details:
- What values do you get extacly? What values did you expected?

We only can fish
 
Last edited:
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User

Could somebody check on their phone how long this query takes:

WITH RECURSIVE input(sud) AS (VALUES('53..7....6..1.5....98....6.8...6...34..8.3..17...2...6.6....2.....4.9..5....8..79')), digits(z, lp) AS (VALUES('1', 1) UNION ALL SELECT CAST(lp + 1 AS TEXT), lp + 1 FROM digits WHERE lp < 9), x(s, ind) AS (SELECT sud, instr(sud, '.') FROM input UNION ALL SELECT substr(s, 1, ind - 1) || z || substr(s, ind + 1), instr(substr(s, 1, ind - 1) || z || substr(s, ind + 1), '.') FROM x, digits AS z WHERE ind > 0 AND NOT EXISTS (SELECT 1 FROM digits AS lp WHERE z.z = substr(s, ((ind - 1) / 9) * 9 + lp, 1) OR z.z = substr(s, ((ind - 1) %9) + (lp - 1) * 9 + 1, 1) OR z.z = substr(s, (((ind - 1)/3) % 3) * 3 + ((ind - 1) / 27) * 27 + lp + ((lp - 1) / 3) * 6, 1))) SELECT s as solution FROM x WHERE ind = 0 order by s asc

RBS
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
How should we use this query without having the Database needed (tables)?

Edit: ok, i run the quer and i saw it just uses temporary tables.

The Query took 1ms here. So 25 (your result) may be ok if your device is not as fast.
 
Last edited:
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
How should we use this query without having the Database needed (tables)?

Edit: ok, i run the quer and i saw it just uses temporary tables.

The Query took 1ms here. So 25 (your result) may be ok if your device is not as fast.

Ok, then I think the answer is simply that SQLite is a lot faster on phone than I expected. I got 1 msec for this query as well on a sd card on a fast Samsung S9.
Get this way slower on a fast PC.

RBS
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Get this way slower on a fast PC.
I´m not that i understand this sentence.
It is slower on a Fast PC (using B4J?)?

Edit: Yes, it took 337ms on my Windows 10 (Intel I7) PC
I guess the "blottleneck" here is the JDBC Driver
 
Last edited:
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
I´m not that i understand this sentence.
It is slower on a Fast PC (using B4J?)?

Edit: Yes, it took 337ms on my Windows 10 (Intel I7) PC
I guess the "blottleneck" here is the JDBC Driver

It is a lot slower on my PC (way slower means a lot slower).
Not sure what exactly you mean with bottleneck is the JDBC driver.
I don't use a JDBC driver on the PC. On the PC I use a C dll.
With that that I get about 425 ms.

RBS
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…