Author Topic: Whats faster, Scripting vs Programming?  (Read 1269 times)

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Whats faster, Scripting vs Programming?
« on: April 13, 2014, 06:05:39 pm »


               This is a silly question, and I suspect the answer is Programming, but I'd like to hear peoples opinions on this.


I've recently got back into nwnx development, and managed to port some of the functionality over to c# which is what I am more akin to, than c++.

So my question is this, lets imagine you have a translation function in nwnscript, that loops through a string, and replaces characters with other combinations of characters, to form a pseudo translated string.

Eg: Common to Pixie for example.


This functionality in nwnscript, from a technical point of view seems like it might involve alot more opcalls and internal method calls, than just having the method in a programming language.
(Im taking an example from SimTools here)

I'm just wondering if performance-wise, is there benefit to porting long operations such as this, to a nwnx method, which then returns the translated string back to nwn?

I am also trying to build a system that can translate pixie back to common.
In simtools, this isn't actually done, SimTools just sends the message to the people who know the language, before it is translated, and then speaks the translated version out loud for other observers to hear.

What I am attempting to do, is have it so players could actually type in the Pixie phrases, and then have them translated to English (Common)

Unfortunately, the backwards translation is not as easy as the Common to Pixie.


string ConvertPixie(string sLetter)
{
    if (GetStringLength(sLetter) > 1)
        sLetter = GetStringLeft(sLetter, 1);
    string sTranslate = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    int iTrans = FindSubString(sTranslate, sLetter);

    switch (iTrans)
    {
        case 0: return "eg";
        case 1: return "o";
        case 2: return "s";
        case 3: return "";
        case 4: return "it";
        case 5: return "th";
        case 6: return "oo";
        case 7: return "n";
        case 8: return "e";
        case 9: return "ta";
        case 10: return "";
        case 11: return "an";
        case 12: return "a";
        case 13: return "ei";
        case 14: return "i";
        case 15: return "k";
        case 16: return "ca";
        case 17: return "t";
        case 18: return "l";
        case 19: return "m";
        case 20: return "ya";
        case 21: return "d";
        case 22: return "v";
        case 23: return "p";
        case 24: return "ni";
        case 25: return "z";
        case 26: return "Eg";
        case 27: return "O";
        case 28: return "S";
        case 29: return "'";
        case 30: return "It";
        case 31: return "Th";
        case 32: return "Oo";
        case 33: return "N";
        case 34: return "E";
        case 35: return "Ta";
        case 36: return "'";
        case 37: return "An";
        case 38: return "A";
        case 39: return "Ei";
        case 40: return "I";
        case 41: return "K";
        case 42: return "Ca";
        case 43: return "T";
        case 44: return "L";
        case 45: return "M";
        case 46: return "Ya";
        case 47: return "D";
        case 48: return "V";
        case 49: return "P";
        case 50: return "Ni";
        case 51: return "Z";
        default: return sLetter;
    }
    return "";
}
Seems when Pixie language was made in Simtools, no such 1 to 1 mapping.
Anyone see any potential ways to translate from Pixie, back to English - given the alphabet you see above?
Capitol D and K both share the ' character, which means the returned string would be kinda ambiguous.


Oooh, I just thought... Because im using C#, I could actually interface this to online translation services?
               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Whats faster, Scripting vs Programming?
« Reply #1 on: April 13, 2014, 06:09:48 pm »


               This post has actually given me some ideas?

I have alot of Spanish and Brazilian Players, who hate having to speak english for the rest of us.
I could have a system in place that takes what they say (onChatHook), try to translate it (C# WebRequest to OnLine Translation (Google Translate?)), if successful, cache it on the server (for future use to save on requests), then send that to the English Players: and Vice Versa...
               
               

               
            

Legacy_virusman

  • Sr. Member
  • ****
  • Posts: 448
  • Karma: +0/-0
Whats faster, Scripting vs Programming?
« Reply #2 on: April 14, 2014, 11:07:12 am »


               

Is this a really long operation? Have you measured the time it takes? If it's a few miliseconds or less, it's not worth moving outside NWScript. Chat events don't happen that often, AI scripts will still take most of the resources.



               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Whats faster, Scripting vs Programming?
« Reply #3 on: April 14, 2014, 01:28:54 pm »


               

Hi Virusman,


I guess my question was posing a bad example, but in general executing a single line of nwScript, that then invoked a c++ method within nwnx for instance.


If that nwnx method carried out dozens of operations - like as you say, AI Calculations etc.


Would there be an overall improvement in performance.


 


In my own head, at the very least: you would be bypassing the VirtualMachine call for each of those dozen operations.


               
               

               
            

Legacy_virusman

  • Sr. Member
  • ****
  • Posts: 448
  • Karma: +0/-0
Whats faster, Scripting vs Programming?
« Reply #4 on: April 14, 2014, 02:26:52 pm »


               

Sure, it'll be faster (although we also have to count the NWNX overhead - if you're sending commands via a string, generating and parsing it may add some overhead), but as with any optimization, the question is - is it worth it? If it's just a few miliseconds, you may end up raising the complexity of the system for performance gain that's not noticeable.



               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Whats faster, Scripting vs Programming?
« Reply #5 on: April 14, 2014, 06:41:41 pm »


               

On this one I would say plan for the future.   The main problem with language translation is not going to be the speed of the script.   It is going to end up being the istruction count.  Now given it is not a problem for chat commands, but if you ever want to extend it it handle translations for  books or notes, you will end up with an instruction count problem running it through the VM.    The last time i was playing around with it, I had to cut the string up into I think it was 500 character strings in order to advoid the TMI.   


 


As far a reverse translation,   THe best bet is to set it up so you never have to do it.     Always keep a copy of the original common string when translating.  that way you will never have to translate back to common. Just swap the string back out for the original.



               
               

               
            

Legacy_Zwerkules

  • Hero Member
  • *****
  • Posts: 1997
  • Karma: +0/-0
Whats faster, Scripting vs Programming?
« Reply #6 on: April 14, 2014, 06:57:50 pm »


               



So my question is this, lets imagine you have a translation function in nwnscript, that loops through a string, and replaces characters with other combinations of characters, to form a pseudo translated string.




 


If you only want a pseudo-language which just replaces some characters by others, a script will surely be the better way, especially since the one you wrote could be optimised a lot by just using 26 lower case letters and change a letter to upper case when needed.


               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Whats faster, Scripting vs Programming?
« Reply #7 on: April 14, 2014, 07:42:12 pm »


               

As long as you have to write the script from the inside of nwn in nwscript, there is no point of porting the code to the external language.


 


To be efficient and comfortable, you would need to do it differently. Change the engine so it looks in the external folder for a perl/ruby/etc. script and executing it instead of *.ncs one.



               
               

               
            

Legacy_leo_x

  • Sr. Member
  • ****
  • Posts: 403
  • Karma: +0/-0
Whats faster, Scripting vs Programming?
« Reply #8 on: April 14, 2014, 10:13:06 pm »


               

That function looks like it would allocate/deallocate strings like crazy (supposing every string on the stack has to be reallocted, which I think is true), aside from any TMI you might hit.  Whether it makes any difference, I don't know...  If you're concerned on a level of principle, do it in C++.