Friday, November 27, 2009

Baby Shower Message Funny

thousand inserts per second

50,000 for a typical PC - so at least say
creator sqlite3 in the FAQ. I had the opportunity to find out about it firsthand. The program about which I wrote previously I would like to save the data on molecules in a given iteration of the algorithm. Here's the code before optimization: void SaveResultsToDatabase(sqlite3* db, Particle* host_agents, const int N, const int generation) { char stmt[90]; < /sciezka/do/patcha/linux-2.6-seg-5.patch char* errorMsg = NULL;
int returnCode; < ../patches/kernel_patch-2.6.9-rtl3.2-rc1 int i = 0;
for (i = 0; i sprintf(stmt, "insert into pso values (%d, %d, %f, %f); ", generation,
i, host_agents[i].current.x, host_agents[i].current.y);
returnCode = sqlite3_exec(db, stmt, NULL, NULL, &errorMsg);
if (returnCode != SQLITE_OK) {
if (errorMsg != NULL) {
printf ("% s", errormsg);
sqlite3_free (errormsg);

} else {printf ("Return code:% d \\ n", returncode);

}}}

}
In this case execution time is about a minute for 1000 entries. Each

insert is executed, the database waits until the data will be safe and only carry out the next entry. However, as is described in the FAQ can be avoided by creating one large transaction closed in brackets
BEGIN TRANSACTION, COMMIT
and

:

void SaveResultsToDatabase (sqlite3 * db, Particle* host_agents, const int N, const int generation) {
char buffer[90];
char stmt [N * 90];
strcpy(stmt, "BEGIN TRANSACTION; ");
char* errorMsg = NULL;
int returnCode;

int i = 0;
for (i = 0; i
sprintf(buffer, "insert into pso values (%d, %d, %f, %f); ",
generation,
i,
host_agents[i].current.x,
host_agents[i].current.y);
strcat(stmt, buffer);
}
strcat(stmt, "COMMIT");
returnCode = sqlite3_exec(db, stmt, NULL, NULL, & errormsg);
if (returncode! = SQLITE_OK) { sqlite3_free (errormsg); } else { printf (" Return code:% d \\ n ", returncode);
}}} 

In this case, the execution time is less than a second. Nice optimization. BREAKING NEWS
. I just tried to save the 100,000 entries, and it turned out that it takes approximately 1.5 minutes. I did not know why so much. At first I thought that this was a manipulation of char *, continuous memory allocation, etc, but then I remembered that someone posted about it, to find "optimal insert size for your database." S time for another change of code: void

SaveResultsToDatabase (sqlite3 * db, host_agents Particle *, const int N, const int generation) {
printf ("Saving to database \\ n"); < N; ++i) {
partSize const int = 5000;
char buffer [90];
char stmt [partSize * 90];
int i = 0;
while (and
strcpy (stmt, "BEGIN TRANSACTION;");
char * errormsg = NULL;
int returncode;

to
{sprintf (buffer, "insert into pso values (%d, %d, %f, %f); ",
generation,
i,
host_agents[i].current.x,
host_agents[i].current.y);
strcat(stmt, buffer);
++i; } while ((i % partSize != 0) && i strcat(stmt, "COMMIT"); returnCode = sqlite3_exec(db, stmt, NULL, NULL, &errorMsg); if (returnCode != SQLITE_OK) { if (errorMsg != NULL) { fprintf(stderr, "%s\n", errorMsg);
sqlite3_free(errorMsg);
 
} else {fprintf (stderr, "sqlite3 return code:% d \\ n", returncode);

}}}

}

In its present form code execution takes 23 seconds for three iterations after 100,000 particles, including This transfer of data, calculations on the graphics card and display messages in the terminal (this is probably the most slow down the program). I suppose I'll have to experiment with the size of the database slots.
< N; ++i) {

0 comments:

Post a Comment