View previous topic :: View next topic |
Author |
Message |
Morrandir
Joined: 13 Jan 2006 Posts: 27
|
Posted: Sat Jan 06, 2007 22:59 Post subject: NWNX4Clock vs NWNX MySQL |
|
|
Hello there!
My first question goes to kungfoowiz:
Do you plan to implement a function GetCurrentTimestamp(), which returns the current Unix timestamp from the machine?
Second question is for both Papillon and kungfoowiz:
Considering server performance, is it better then to use the GetTime() function from nwnx4clock or do a mysql query "select NOW()"?
Thanks for your work, btw. _________________ German NWN1/2 Persistent World Hochwaldallianz |
|
Back to top |
|
|
Morrandir
Joined: 13 Jan 2006 Posts: 27
|
Posted: Sun Jan 07, 2007 20:51 Post subject: |
|
|
I can answer the second question myself - I think this is quite interesting for some of you guys.
I just measured time of getting the current time with a "select now()" query on the one hand, and with GetSystemTime() (from NWNXclock) on the other hand 500 times each.
NWNXClock: 10 miliseconds
NWNXSQL: 3 seconds
_________________ German NWN1/2 Persistent World Hochwaldallianz |
|
Back to top |
|
|
kungfoowiz
Joined: 12 Oct 2006 Posts: 61
|
Posted: Mon Jan 08, 2007 12:52 Post subject: |
|
|
Hello Morrandir
I haven't had much time to play around with NWNX4 lately due to work commitments, rest assured I'll put some time into it this week.
Yes, I'll put in UNIX-style timestamping. My other bud actually asked me for that a couple weeks back. Consider it officially on the feature list and I'll update the plugin this week for you.
I can only surmise that the extra time there is incurred due to waiting for the string data to pass between the various programs like so:
NWN2 <-> NWNX4Clock
NWN2 <-> NWNX4MySQL <-> MySQL DB
---
kung |
|
Back to top |
|
|
Disco
Joined: 06 Dec 2006 Posts: 152
|
Posted: Mon Jan 08, 2007 14:12 Post subject: |
|
|
Mind that NOW() doesn't give you a UNIX timestamp, but a MySQL timestamp.
YYYY-MM-DD HH:MM:SS = MySQL
Seconds from 1970 = UNIX
I asked Kung to make this (well, I actually don't care if it starts counting from 1-1-2007) to use it for long delay blocks, such as on disabled spawn triggers.
I hope he makes it NWN2 compatible as well... please? |
|
Back to top |
|
|
virusman
Joined: 30 Jan 2005 Posts: 1020 Location: Russia
|
Posted: Mon Jan 08, 2007 16:10 Post subject: |
|
|
Morrandir wrote: | NWNXSQL: 3 seconds:) | 3 seconds?! That's almost impossible. |
|
Back to top |
|
|
Morrandir
Joined: 13 Jan 2006 Posts: 27
|
Posted: Mon Jan 08, 2007 18:37 Post subject: |
|
|
kungfoowiz wrote: |
Yes, I'll put in UNIX-style timestamping. My other bud actually asked me for that a couple weeks back. Consider it officially on the feature list and I'll update the plugin this week for you. |
Thanks very much!
Disco wrote: | Mind that NOW() doesn't give you a UNIX timestamp, but a MySQL timestamp.
YYYY-MM-DD HH:MM:SS = MySQL
Seconds from 1970 = UNIX |
Yes, sure. But what I needed in my scripts was the current hour.
So I had the choice between GetSystemTime() and "select now()" and retreive the hour with GetSubString().
virusman wrote: | Morrandir wrote: | NWNXSQL: 3 seconds | 3 seconds?! That's almost impossible. |
That's the total time for 500 queries.
Give it a try. _________________ German NWN1/2 Persistent World Hochwaldallianz |
|
Back to top |
|
|
Papillon x-man
Joined: 28 Dec 2004 Posts: 1060 Location: Germany
|
Posted: Mon Jan 08, 2007 23:56 Post subject: |
|
|
Retrieving 500 rows from MySQL takes 22 milliseconds, and now you say that getting the current time takes like ... 150 times longer ? There is something very wrong here . _________________ Papillon |
|
Back to top |
|
|
Morrandir
Joined: 13 Jan 2006 Posts: 27
|
Posted: Tue Jan 09, 2007 9:26 Post subject: |
|
|
Well... I'll post the code tonight (as I'm not at home atm).
I just don't think there are things in it, that can be 'wrong'.
It's just a for-loop with 500 iterations, and inside is a "select now()" query. Afterwards from the resulting string the hour is retreived with GetSubstring().
And.. well... think it makes quite a difference if you retreive 500 rows with one single SELECT statement or if you do 500 seperate SELECT statements, doesn't it? _________________ German NWN1/2 Persistent World Hochwaldallianz |
|
Back to top |
|
|
Papillon x-man
Joined: 28 Dec 2004 Posts: 1060 Location: Germany
|
Posted: Tue Jan 09, 2007 12:19 Post subject: |
|
|
Oh, I'm not saying that something in your test has to be wrong, but somewhere in the chain of communication there is something slowing things down. Maybe the GetSubString function eats up a lot of time as well ? _________________ Papillon |
|
Back to top |
|
|
Morrandir
Joined: 13 Jan 2006 Posts: 27
|
Posted: Tue Jan 09, 2007 20:00 Post subject: |
|
|
Well then, have a look at this:
Code: | #include "nwnx_clock"
#include "nwnx_time"
#include "nwnx_sql"
// retreive current hour with NWNXClock
int GetSystemHour(){
string sTime = GetSystemTime();
return StringToInt(GetSubString(sTime, 0, 2));
}
//retreive current hour with NWNXClock
int GetCurrentHour(){
string sQuery = "select now()";
SQLExecDirect(sQuery);
if (SQLFetch() == SQL_SUCCESS){
return StringToInt(GetSubString(SQLGetData(1), 11, 2));
} else {
return -1;
}
}
void main(){
object oPC = GetLastUsedBy();
object oModule = GetModule();
int i;
int j = 500;
float fTime;
StartTimer(oModule, "NWNXclock");
for(i=0; i <= j; i++){
GetSystemHour();
}
fTime = StringToFloat(StopTimer(oModule, "NWNXclock")) / 1000;
SendMessageToPC(oPC, IntToString(j) + " times with NWNXclock took " + FloatToString(fTime) + " ms");
StartTimer(oModule, "MySQL");
for(i=0; i <= j; i++){
GetCurrentHour();
}
fTime = StringToFloat(StopTimer(oModule, "MySQL")) / 1000;
SendMessageToPC(oPC, IntToString(j) + " times with MySQL took " + FloatToString(fTime) + " ms");
SendMessageToPC(oPC, "-----------------------");
} |
I'm using GetSubString() in both functions.
The values I get approximately are the same as I posted in above. _________________ German NWN1/2 Persistent World Hochwaldallianz |
|
Back to top |
|
|
Gryphyn
Joined: 20 Jan 2005 Posts: 431
|
Posted: Tue Jan 09, 2007 23:49 Post subject: |
|
|
not exactly a fair comparison...
GetSubString(...,0,2) will always be faster that GetSubString(...,11,2)
-- but not by that much
what speeds do you get with
//retreive current hour with NWNXClock
const string sQuery = "select now()";
int GetCurrentHour(){
SQLExecDirect(sQuery);
if (SQLFetch() == SQL_SUCCESS){
string sData = SQLGetData(1);
return StringToInt(GetSubString(sData, 11, 2));
} else {
return -1;
}
}
*curiosity factor - in theory it should be faster than the original
Cheers
Gryphyn |
|
Back to top |
|
|
virusman
Joined: 30 Jan 2005 Posts: 1020 Location: Russia
|
Posted: Wed Jan 10, 2007 0:53 Post subject: |
|
|
Morrandir wrote: | virusman wrote: | Morrandir wrote: | NWNXSQL: 3 seconds | 3 seconds?! That's almost impossible. |
That's the total time for 500 queries.
Give it a try. | Ah, sorry, I missed that. |
|
Back to top |
|
|
Disco
Joined: 06 Dec 2006 Posts: 152
|
Posted: Wed Jan 10, 2007 12:40 Post subject: |
|
|
Morrandir wrote: |
Disco wrote: | Mind that NOW() doesn't give you a UNIX timestamp, but a MySQL timestamp.
YYYY-MM-DD HH:MM:SS = MySQL
Seconds from 1970 = UNIX |
Yes, sure. But what I needed in my scripts was the current hour.
So I had the choice between GetSystemTime() and "select now()" and retreive the hour with GetSubString().
|
The only thing I wanted to mention that if you ask for a plugin with UNIX time you won't be able to use it to get the hour. Unless you want to do the recalculations from the start of the UNIX epoch in NWNscript, of course.
It might be nitpicking, but since I asked Kung to make a UNIX time generator, instead of a date importer, I thought it would be good to warn you about the difference. |
|
Back to top |
|
|
Morrandir
Joined: 13 Jan 2006 Posts: 27
|
Posted: Wed Jan 10, 2007 16:42 Post subject: |
|
|
@Gryphyn
I'll give it a try without GetSubString() at all tonight.
I've heard before that String functions are quite expensive in NWN, but I don't really think, that should make such a difference, as you mentioned yourself.
@Disco
Yes, I know about the difference.
I just need a UNIX timestamp for another system, to test if two points of time differ more than a certain time span.
And if this will be as fast as GetSystemTime, I'll rather use NWNXClock than NWNXMySQL. _________________ German NWN1/2 Persistent World Hochwaldallianz |
|
Back to top |
|
|
Morrandir
Joined: 13 Jan 2006 Posts: 27
|
Posted: Wed Jan 10, 2007 21:02 Post subject: |
|
|
I just removed the GetSubString() function and returned a string instead:
Code: |
// retreive current hour with NWNXClock
string GetSystemHour(){
return GetSystemTime();
}
//retreive current hour with NWNXClock
string GetCurrentHour(){
string sQuery = "select now()";
SQLExecDirect(sQuery);
if (SQLFetch() == SQL_SUCCESS){
return SQLGetData(1);
} else {
return "";
}
}
void main(){
object oPC = GetLastUsedBy();
object oModule = GetModule();
int i;
int j = 500;
float fTime;
StartTimer(oModule, "NWNXclock");
for(i=0; i <= j; i++){
GetSystemHour();
}
fTime = StringToFloat(StopTimer(oModule, "NWNXclock")) / 1000;
SendMessageToPC(oPC, IntToString(j) + " times with NWNXclock took " + FloatToString(fTime) + " ms");
StartTimer(oModule, "MySQL");
for(i=0; i <= j; i++){
GetCurrentHour();
}
fTime = StringToFloat(StopTimer(oModule, "MySQL")) / 1000;
SendMessageToPC(oPC, IntToString(j) + " times with MySQL took " + FloatToString(fTime) + " ms");
SendMessageToPC(oPC, "-----------------------");
} |
Test results are the same.
Could someone please test this, too? _________________ German NWN1/2 Persistent World Hochwaldallianz |
|
Back to top |
|
|
|