[Snippet]Efficient command
#1

Код:
//edit:1
if(strcmp("/bla",cmdtext) == 0)
A bit slower than
Код:
//edit:2
if(!strcmp("/bla",cmdtext))
A bit slower than
Код:
edit:3
if(!strcmp("bla",cmdtext[1]))
And time analysis&code
pawn Код:
#include <a_samp>

main(){}

public OnGameModeInit(){
  OnPlayerCommandText(0,"/test");
  return true;
}

public OnPlayerCommandText(playerid,cmdtext[]){
  for(new j;j<10;j++){
  new
    t1,t2,t3,t4,t5;
  t1 = GetTickCount();
  for(new i; i < 10000000;i++){
    if(!strcmp("test",cmdtext[1])){}
  }
  t2 = GetTickCount();
  for(new i; i < 10000000;i++){
    if(strcmp("test",cmdtext[1]) == 0){}
  }
  t3 = GetTickCount();
  for(new i; i < 10000000;i++){
    if(!strcmp("/test",cmdtext)){}
  }
  t4 = GetTickCount();
  for(new i; i < 10000000;i++){
    if(strcmp("/test",cmdtext) == 0){}
  }
  t5 = GetTickCount();
  printf("-%d-%d-%d-%d-",t2-t1,t3-t2,t4-t3,t5-t4);
  }
  return true;
}
Код:
[10:22:59] -1266-1406-1313-1453-
[10:23:05] -1265-1407-1296-1454-
[10:23:10] -1265-1406-1313-1453-
[10:23:16] -1266-1406-1297-1453-
[10:23:21] -1281-1406-1297-1438-
[10:23:26] -1265-1422-1297-1453-
[10:23:32] -1266-1406-1313-1437-
[10:23:37] -1281-1407-1297-1453-
[10:23:43] -1281-1406-1297-1453-
[10:23:48] -1266-1406-1313-1437-
As we can see, edit:3 is faster than anyother edition.
Would anyone use edit:3 to make command in the future?
Reply


Messages In This Thread
[Snippet]Efficient command - by yezizhu - 27.07.2009, 03:13
Re: [Snippet]Command - by [DD]FlameOFDeath - 27.07.2009, 03:23
Re: [Snippet]Command - by yezizhu - 27.07.2009, 03:27
Re: [Snippet]Command - by [DD]FlameOFDeath - 27.07.2009, 03:29
Re: [Snippet]Command - by yezizhu - 27.07.2009, 03:36
Re: [Snippet]Command - by [DD]FlameOFDeath - 27.07.2009, 03:38
Re: [Snippet]Command - by yezizhu - 27.07.2009, 12:13
Re: [Snippet]Command - by ғαιιοцт - 04.08.2009, 14:27
Re: [Snippet]Command - by yezizhu - 04.08.2009, 16:21
Re: [Snippet]Command - by ғαιιοцт - 04.08.2009, 16:22

Forum Jump:


Users browsing this thread: 1 Guest(s)