Quantcast

Jump to content

» «
Photo

[WIP]Test Script for script speed

8 replies to this topic
Nevitro
  • Nevitro

    Modder

  • Members
  • Joined: 31 Mar 2009

#1

Posted 11 May 2013 - 05:26 PM Edited by Nevitro, 11 May 2013 - 05:32 PM.

Hello programmers. First, there is my code [copy that and paste into txt file, after that name this "Nevitrotest.cs"]:
CODE

using System;
using System.Windows.Forms;
using GTA;
namespace Nevitrotest
{
public class SCRIPT_SPEED_TEST : Script
{
bool run_test=false;
double summarum;
int time_run,time_run_limit=10,x,interval=0;
int[] getallx = new int[10];
 public SCRIPT_SPEED_TEST()
 {
       this.Tick += this.TICK_DO_ALL_TIME;
 Game.Console.Print("------------------------------\n Nevitro script testing how much time run script with different Interval\n Type 'nvconfig' or 'nvtest'");
 BindConsoleCommand("nvtest", new ConsoleCommandDelegate(RUN_TEST));
 BindConsoleCommand("nvconfig", new ConsoleCommandDelegate(TEST_CONFIG));
 }
public void RUN_TEST(ParameterCollection Parameter)
{
Game.Console.Print("Please wait... Test will run in :");
Wait(1000);
Game.Console.Print("3...");
Wait(1000);
Game.Console.Print("2..");
Wait(1000);
Game.Console.Print("1...");
Wait(1000);
Game.Console.Close();
Game.DisplayText("Testing script speed RUN");
run_test = true;
x=0;
time_run=1;
summarum=0;
GTA.Native.Function.Call("SETTIMERC", 0);
}
public void TEST_CONFIG(ParameterCollection Parameter)
{
Wait(100);
Game.Console.Close();
Game.Console.Print("\n------------------INTERVAL CONFIG NEVITRO SCRIPT\n Please, close this console and set interval with UP/DOWN arrows.\n At the end, please press Enter.\n If You do not want change interval, just press Enter after close console\n TIP: Bigger interval will give smaller amount speed of script. \n Scripts should run lees times than normal [interval=0]");
Game.DisplayText("How big interval for script You want?");

do {
Player.CanControlCharacter = false;
if (Game.isKeyPressed(Keys.Up))
{
interval=interval+1;
Game.DisplayText("Interval ="+interval);
}
if (Game.isKeyPressed(Keys.Down))
{
interval=interval-1;
if (interval<0) interval=0;
Game.DisplayText("Interval ="+interval);
}
Wait(20);
}while (!(Game.isKeyPressed(Keys.Enter)));
Wait(100);
Game.Console.Print("\n------------------HOW MUCH TEST CONFIG NEVITRO SCRIPT\n Please, close this console and set how much tests You want with UP/DOWN arrows.\n At the end, please press Enter.\n If You do not want change amount of tests, just press Enter after close console\n Bigger amount mean more accurate results. \n");
Game.DisplayText("How much tests You want? for script You want?");
do{
Player.CanControlCharacter = false;
if (Game.isKeyPressed(Keys.Up))
{
time_run_limit=time_run_limit+1;
Game.DisplayText("Amount of tests ="+time_run_limit);
}
if (Game.isKeyPressed(Keys.Down))
{
time_run_limit=time_run_limit-1;
if (time_run_limit<1) time_run_limit=1;
Game.DisplayText("Amount of tests ="+time_run_limit);
}
Wait(50);
}while (!(Game.isKeyPressed(Keys.Enter)));
Player.CanControlCharacter = true;
Game.Console.Open();
Game.Console.Print("Interval of script is "+interval+" ms");
Game.Console.Print("Amount tests of script is "+time_run_limit+"\n");
Game.Console.Print("Type here 'nvtest'");
}
   public void TICK_DO_ALL_TIME(object sender, EventArgs e)
   {

 if (run_test==true)
 {
  if (GTA.Native.Function.Call<int>("TIMERC")<1000)
  {
  x=x+1;
  Wait(interval);
  }
  else
  {
  Game.DisplayText("Testing speed ...");
  getallx[time_run-1]=x;
  Game.Console.Print("Test "+time_run+" run "+x+" times.");
  time_run=time_run+1;
  x=0;
  GTA.Native.Function.Call("SETTIMERC", 0);
   if (time_run==(time_run_limit+1))
   {
   for (int xyz=0; xyz<=9; xyz++)
   {
   summarum=summarum+getallx[xyz];
   }
   summarum=summarum/time_run_limit;
   run_test=false;
   Game.Console.Print("AVG times how much run script: "+Math.Round(summarum,0)+"\nwith interval: "+interval+"\nand with "+time_run_limit+" tests");
   Game.DisplayText("Testing script speed STOP");
   Game.Console.Open();
   }
  }
 }
}
}
}


Codes allowed in game console:
"nvconfig"
"nvtest"

nvconfig is for set interval and limits tests in game. Interval is it time before script do next loop. Second option, limit of tests, allow to user make very accurace test. Bigger value give more precise results.

nvtest - make test. When test run, You can do anything. Also play with others scripts.

Instructions:
This scripts generaly is for developers, but also normal user can use this like benchmark for scripts.
If interval is 0 and You have big amount of AVG it is good. If Your AVG amount is under 20 - Your computer must really work hard now. Try to disable some programs in Windows and run again this test. Better? Please write here.

Developer on this script, can see what is difference for computer if interval is not set to 1 or 2... Why i say this? Because in GTA 4, many programmist think everyone super computer. Why script must check every milisecond what we do? For me, 10 scripts running and added "this.Interval = 1" make my game run faster... Only 1 ms for every script...
So, with my script You can see in different locations, situations how many loops do script. Your script also should do same amount of loops.

I just left for You to fun. Small, fast benchmark wink.gif

Forgot, my results [5 AVG for one situation]:
Small window, the lowest graphic, interval 0, place near house: 26, 25, 24,26,25
Fullscreen, medium graphic, interval 0, that same place: 15,16,17,16,16
Fullscreen, medium graphic, interval 1, that same place: 16,16,16,15,14

1 loop less, for simple x=x+1 script... what should if You put there some more diffucult things to do? I do not have time for this now, but test for Yourself smile.gif

julionib
  • julionib

    Coder

  • Members
  • Joined: 13 Sep 2012
  • Brazil

#2

Posted 12 May 2013 - 02:30 PM

i use 10 ms of interval, what kills me is the lag ares where Wait(1000) wait more than one sec hehe

Nevitro
  • Nevitro

    Modder

  • Members
  • Joined: 31 Mar 2009

#3

Posted 12 May 2013 - 04:40 PM

Must add limit for more than 1000 ms smile.gif

blowjobcumpussy
  • blowjobcumpussy

    Player Hater

  • BUSTED!
  • Joined: 10 May 2013

#4

Posted 13 May 2013 - 05:01 AM

nice i will test myself soon, btw u can do x++; instead of x = x+ 1; wink.gif

Nevitro
  • Nevitro

    Modder

  • Members
  • Joined: 31 Mar 2009

#5

Posted 13 May 2013 - 11:57 AM

Yeah i know, but sometimes if didn't work i just write to more simple [for me] code... I use "x++" most times only in For wink.gif

pedro2555
  • pedro2555

    Open Sourcer

  • Members
  • Joined: 02 Sep 2012
  • Portugal

#6

Posted 13 June 2013 - 11:23 PM

Sorry if I look out of place, but what exactly TIMERC returns ?

Nevitro
  • Nevitro

    Modder

  • Members
  • Joined: 31 Mar 2009

#7

Posted 14 June 2013 - 09:32 AM

It is game timer, return miliseconds in "int".


Jakes625
  • Jakes625

    Player Hater

  • Members
  • Joined: 06 Jul 2013

#8

Posted 06 July 2013 - 01:28 PM

QUOTE (Nevitro @ Saturday, May 11 2013, 17:26)
Hello programmers. First, there is my code [copy that and paste into txt file, after that name this "Nevitrotest.cs"]:
CODE

using System;
using System.Windows.Forms;
using GTA;
namespace Nevitrotest
{
public class SCRIPT_SPEED_TEST : Script
{
bool run_test=false;
double summarum;
int time_run,time_run_limit=10,x,interval=0;
int[] getallx = new int[10];
 public SCRIPT_SPEED_TEST()
 {
       this.Tick += this.TICK_DO_ALL_TIME;
 Game.Console.Print("------------------------------\n Nevitro script testing how much time run script with different Interval\n Type 'nvconfig' or 'nvtest'");
 BindConsoleCommand("nvtest", new ConsoleCommandDelegate(RUN_TEST));
 BindConsoleCommand("nvconfig", new ConsoleCommandDelegate(TEST_CONFIG));
 }
public void RUN_TEST(ParameterCollection Parameter)
{
Game.Console.Print("Please wait... Test will run in :");
Wait(1000);
Game.Console.Print("3...");
Wait(1000);
Game.Console.Print("2..");
Wait(1000);
Game.Console.Print("1...");
Wait(1000);
Game.Console.Close();
Game.DisplayText("Testing script speed RUN");
run_test = true;
x=0;
time_run=1;
summarum=0;
GTA.Native.Function.Call("SETTIMERC", 0);
}
public void TEST_CONFIG(ParameterCollection Parameter)
{
Wait(100);
Game.Console.Close();
Game.Console.Print("\n------------------INTERVAL CONFIG NEVITRO SCRIPT\n Please, close this console and set interval with UP/DOWN arrows.\n At the end, please press Enter.\n If You do not want change interval, just press Enter after close console\n TIP: Bigger interval will give smaller amount speed of script. \n Scripts should run lees times than normal [interval=0]");
Game.DisplayText("How big interval for script You want?");

do {
Player.CanControlCharacter = false;
if (Game.isKeyPressed(Keys.Up))
{
interval=interval+1;
Game.DisplayText("Interval ="+interval);
}
if (Game.isKeyPressed(Keys.Down))
{
interval=interval-1;
if (interval<0) interval=0;
Game.DisplayText("Interval ="+interval);
}
Wait(20);
}while (!(Game.isKeyPressed(Keys.Enter)));
Wait(100);
Game.Console.Print("\n------------------HOW MUCH TEST CONFIG NEVITRO SCRIPT\n Please, close this console and set how much tests You want with UP/DOWN arrows.\n At the end, please press Enter.\n If You do not want change amount of tests, just press Enter after close console\n Bigger amount mean more accurate results. \n");
Game.DisplayText("How much tests You want? for script You want?");
do{
Player.CanControlCharacter = false;
if (Game.isKeyPressed(Keys.Up))
{
time_run_limit=time_run_limit+1;
Game.DisplayText("Amount of tests ="+time_run_limit);
}
if (Game.isKeyPressed(Keys.Down))
{
time_run_limit=time_run_limit-1;
if (time_run_limit<1) time_run_limit=1;
Game.DisplayText("Amount of tests ="+time_run_limit);
}
Wait(50);
}while (!(Game.isKeyPressed(Keys.Enter)));
Player.CanControlCharacter = true;
Game.Console.Open();
Game.Console.Print("Interval of script is "+interval+" ms");
Game.Console.Print("Amount tests of script is "+time_run_limit+"\n");
Game.Console.Print("Type here 'nvtest'");
}
   public void TICK_DO_ALL_TIME(object sender, EventArgs e)
   {

 if (run_test==true)
 {
  if (GTA.Native.Function.Call<int>("TIMERC")<1000)
  {
  x=x+1;
  Wait(interval);
  }
  else
  {
  Game.DisplayText("Testing speed ...");
  getallx[time_run-1]=x;
  Game.Console.Print("Test "+time_run+" run "+x+" times.");
  time_run=time_run+1;
  x=0;
  GTA.Native.Function.Call("SETTIMERC", 0);
   if (time_run==(time_run_limit+1))
   {
   for (int xyz=0; xyz<=9; xyz++)
   {
   summarum=summarum+getallx[xyz];
   }
   summarum=summarum/time_run_limit;
   run_test=false;
   Game.Console.Print("AVG times how much run script: "+Math.Round(summarum,0)+"\nwith interval: "+interval+"\nand with "+time_run_limit+" tests");
   Game.DisplayText("Testing script speed STOP");
   Game.Console.Open();
   }
  }
 }
}
}
}


Codes allowed in game console:
"nvconfig"
"nvtest"

nvconfig is for set interval and limits tests in game. Interval is it time before script do next loop. Second option, limit of tests, allow to user make very accurace test. Bigger value give more precise results.

nvtest - make test. When test run, You can do anything. Also play with others scripts.

Instructions:
This scripts generaly is for developers, but also normal user can use this like benchmark for scripts.
If interval is 0 and You have big amount of AVG it is good. If Your AVG amount is under 20 - Your computer must really work hard now. Try to disable some programs in Windows and run again this test. Better? Please write here.

Developer on this script, can see what is difference for computer if interval is not set to 1 or 2... Why i say this? Because in GTA 4, many programmist think everyone super computer. Why script must check every milisecond what we do? For me, 10 scripts running and added "this.Interval = 1" make my game run faster... Only 1 ms for every script...
So, with my script You can see in different locations, situations how many loops do script. Your script also should do same amount of loops.

I just left for You to fun. Small, fast benchmark wink.gif

Forgot, my results [5 AVG for one situation]:
Small window, the lowest graphic, interval 0, place near house: 26, 25, 24,26,25
Fullscreen, medium graphic, interval 0, that same place: 15,16,17,16,16
Fullscreen, medium graphic, interval 1, that same place: 16,16,16,15,14

1 loop less, for simple x=x+1 script... what should if You put there some more diffucult things to do? I do not have time for this now, but test for Yourself smile.gif

DateTime start = DateTime.Now;

//do stuff

DateTime end = DateTime.Now;

string Duration = (end - start).seconds.ToString();
?

pedro2555
  • pedro2555

    Open Sourcer

  • Members
  • Joined: 02 Sep 2012
  • Portugal

#9

Posted 08 July 2013 - 11:35 PM Edited by pedro2555, 08 July 2013 - 11:38 PM.

QUOTE (Jakes625 @ Saturday, Jul 6 2013, 13:28)
QUOTE (Nevitro @ Saturday, May 11 2013, 17:26)
Hello programmers. First, there is my code [copy that and paste into txt file, after that name this "Nevitrotest.cs"]:
CODE

using System;
using System.Windows.Forms;
using GTA;
namespace Nevitrotest
{
public class SCRIPT_SPEED_TEST : Script
{
bool run_test=false;
double summarum;
int time_run,time_run_limit=10,x,interval=0;
int[] getallx = new int[10];
 public SCRIPT_SPEED_TEST()
 {
       this.Tick += this.TICK_DO_ALL_TIME;
 Game.Console.Print("------------------------------\n Nevitro script testing how much time run script with different Interval\n Type 'nvconfig' or 'nvtest'");
 BindConsoleCommand("nvtest", new ConsoleCommandDelegate(RUN_TEST));
 BindConsoleCommand("nvconfig", new ConsoleCommandDelegate(TEST_CONFIG));
 }
public void RUN_TEST(ParameterCollection Parameter)
{
Game.Console.Print("Please wait... Test will run in :");
Wait(1000);
Game.Console.Print("3...");
Wait(1000);
Game.Console.Print("2..");
Wait(1000);
Game.Console.Print("1...");
Wait(1000);
Game.Console.Close();
Game.DisplayText("Testing script speed RUN");
run_test = true;
x=0;
time_run=1;
summarum=0;
GTA.Native.Function.Call("SETTIMERC", 0);
}
public void TEST_CONFIG(ParameterCollection Parameter)
{
Wait(100);
Game.Console.Close();
Game.Console.Print("\n------------------INTERVAL CONFIG NEVITRO SCRIPT\n Please, close this console and set interval with UP/DOWN arrows.\n At the end, please press Enter.\n If You do not want change interval, just press Enter after close console\n TIP: Bigger interval will give smaller amount speed of script. \n Scripts should run lees times than normal [interval=0]");
Game.DisplayText("How big interval for script You want?");

do {
Player.CanControlCharacter = false;
if (Game.isKeyPressed(Keys.Up))
{
interval=interval+1;
Game.DisplayText("Interval ="+interval);
}
if (Game.isKeyPressed(Keys.Down))
{
interval=interval-1;
if (interval<0) interval=0;
Game.DisplayText("Interval ="+interval);
}
Wait(20);
}while (!(Game.isKeyPressed(Keys.Enter)));
Wait(100);
Game.Console.Print("\n------------------HOW MUCH TEST CONFIG NEVITRO SCRIPT\n Please, close this console and set how much tests You want with UP/DOWN arrows.\n At the end, please press Enter.\n If You do not want change amount of tests, just press Enter after close console\n Bigger amount mean more accurate results. \n");
Game.DisplayText("How much tests You want? for script You want?");
do{
Player.CanControlCharacter = false;
if (Game.isKeyPressed(Keys.Up))
{
time_run_limit=time_run_limit+1;
Game.DisplayText("Amount of tests ="+time_run_limit);
}
if (Game.isKeyPressed(Keys.Down))
{
time_run_limit=time_run_limit-1;
if (time_run_limit<1) time_run_limit=1;
Game.DisplayText("Amount of tests ="+time_run_limit);
}
Wait(50);
}while (!(Game.isKeyPressed(Keys.Enter)));
Player.CanControlCharacter = true;
Game.Console.Open();
Game.Console.Print("Interval of script is "+interval+" ms");
Game.Console.Print("Amount tests of script is "+time_run_limit+"\n");
Game.Console.Print("Type here 'nvtest'");
}
   public void TICK_DO_ALL_TIME(object sender, EventArgs e)
   {

 if (run_test==true)
 {
  if (GTA.Native.Function.Call<int>("TIMERC")<1000)
  {
  x=x+1;
  Wait(interval);
  }
  else
  {
  Game.DisplayText("Testing speed ...");
  getallx[time_run-1]=x;
  Game.Console.Print("Test "+time_run+" run "+x+" times.");
  time_run=time_run+1;
  x=0;
  GTA.Native.Function.Call("SETTIMERC", 0);
   if (time_run==(time_run_limit+1))
   {
   for (int xyz=0; xyz<=9; xyz++)
   {
   summarum=summarum+getallx[xyz];
   }
   summarum=summarum/time_run_limit;
   run_test=false;
   Game.Console.Print("AVG times how much run script: "+Math.Round(summarum,0)+"\nwith interval: "+interval+"\nand with "+time_run_limit+" tests");
   Game.DisplayText("Testing script speed STOP");
   Game.Console.Open();
   }
  }
 }
}
}
}


Codes allowed in game console:
"nvconfig"
"nvtest"

nvconfig is for set interval and limits tests in game. Interval is it time before script do next loop. Second option, limit of tests, allow to user make very accurace test. Bigger value give more precise results.

nvtest - make test. When test run, You can do anything. Also play with others scripts.

Instructions:
This scripts generaly is for developers, but also normal user can use this like benchmark for scripts.
If interval is 0 and You have big amount of AVG it is good. If Your  AVG amount is under 20 - Your computer must really work hard now. Try to disable some programs in Windows and run again this test. Better? Please write here.

Developer on this script, can see what is difference for computer if interval is not set to 1 or 2... Why i say this? Because in GTA 4, many programmist think everyone super computer. Why script must check every milisecond what we do? For me, 10 scripts running and added "this.Interval = 1" make my game run faster... Only 1 ms for every script...
So, with my script You can see in different locations, situations how many loops do script. Your script also should do same amount of loops.

I just left for You to fun. Small, fast benchmark wink.gif

Forgot, my results [5 AVG for one situation]:
Small window, the lowest graphic, interval 0, place near house: 26, 25, 24,26,25
Fullscreen, medium graphic, interval 0, that same place: 15,16,17,16,16
Fullscreen, medium graphic, interval 1, that same place: 16,16,16,15,14

1 loop less, for simple x=x+1 script... what should if You put there some more diffucult things to do? I do not have time for this now, but test for Yourself smile.gif

DateTime start = DateTime.Now;

//do stuff

DateTime end = DateTime.Now;

string Duration = (end - start).seconds.ToString();
?

Actually:
CODE

using System.Diagnostics;

Stopwatch sw = new Stopwatch();

sw.Start();

... do your stuff ...

sw.Stop();

TimeSpan executionTime = sw.Elapsed;


It's the suggested way by Microsoft. It should have negligible delay. And, just to remind, you should make multiple benchmarks.

http://msdn.microsof....stopwatch.aspx




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users