logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
NWNX4Clock vs NWNX MySQL
Goto page 1, 2  Next
 
Post new topic   Reply to topic    nwnx.org Forum Index -> Development
View previous topic :: View next topic  
Author Message
Morrandir



Joined: 13 Jan 2006
Posts: 27

PostPosted: Sat Jan 06, 2007 22:59    Post subject: NWNX4Clock vs NWNX MySQL Reply with quote

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. Smile
_________________
German NWN1/2 Persistent World Hochwaldallianz
Back to top
View user's profile Send private message
Morrandir



Joined: 13 Jan 2006
Posts: 27

PostPosted: Sun Jan 07, 2007 20:51    Post subject: Reply with quote

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

Smile
_________________
German NWN1/2 Persistent World Hochwaldallianz
Back to top
View user's profile Send private message
kungfoowiz



Joined: 12 Oct 2006
Posts: 61

PostPosted: Mon Jan 08, 2007 12:52    Post subject: Reply with quote

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
View user's profile Send private message
Disco



Joined: 06 Dec 2006
Posts: 152

PostPosted: Mon Jan 08, 2007 14:12    Post subject: Reply with quote

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
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Mon Jan 08, 2007 16:10    Post subject: Reply with quote

Morrandir wrote:
NWNXSQL: 3 seconds:)
3 seconds?! That's almost impossible.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Morrandir



Joined: 13 Jan 2006
Posts: 27

PostPosted: Mon Jan 08, 2007 18:37    Post subject: Reply with quote

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! Smile


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. Wink
_________________
German NWN1/2 Persistent World Hochwaldallianz
Back to top
View user's profile Send private message
Papillon
x-man


Joined: 28 Dec 2004
Posts: 1060
Location: Germany

PostPosted: Mon Jan 08, 2007 23:56    Post subject: Reply with quote

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 Razz.
_________________
Papillon
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Morrandir



Joined: 13 Jan 2006
Posts: 27

PostPosted: Tue Jan 09, 2007 9:26    Post subject: Reply with quote

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
View user's profile Send private message
Papillon
x-man


Joined: 28 Dec 2004
Posts: 1060
Location: Germany

PostPosted: Tue Jan 09, 2007 12:19    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website MSN Messenger
Morrandir



Joined: 13 Jan 2006
Posts: 27

PostPosted: Tue Jan 09, 2007 20:00    Post subject: Reply with quote

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
View user's profile Send private message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Tue Jan 09, 2007 23:49    Post subject: Reply with quote

not exactly a fair comparison...
GetSubString(...,0,2) will always be faster that GetSubString(...,11,2)
-- but not by that much Wink

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
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Wed Jan 10, 2007 0:53    Post subject: Reply with quote

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. Wink
Ah, sorry, I missed that.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Disco



Joined: 06 Dec 2006
Posts: 152

PostPosted: Wed Jan 10, 2007 12:40    Post subject: Reply with quote

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
View user's profile Send private message
Morrandir



Joined: 13 Jan 2006
Posts: 27

PostPosted: Wed Jan 10, 2007 16:42    Post subject: Reply with quote

@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. Smile
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
View user's profile Send private message
Morrandir



Joined: 13 Jan 2006
Posts: 27

PostPosted: Wed Jan 10, 2007 21:02    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Development All times are GMT + 2 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group