forward Float:SecondsToMinutes(seconds);
public Float:SecondsToMinutes(seconds)
return ( seconds / 60 );
forward Float:SecondsToMinutes(seconds);
public Float:SecondsToMinutes(seconds)
return ( seconds / 60 );
//under your command/public/stock
new minutes, diff;
minutes = SecondsToMinutes(seconds);
diff = seconds*60;
seconds = diff - minutes
new string[128];
format(string, 128, "Those are %i minutes, and %i seconds.",minutes,seconds);
//:D
new TimeLeft = 500;
stock ConvertSecondsIntoMinute(seconds)
{
//Codes here
format(string,128,"%d:%d",minute,seconds);
return string;
}
new string[128];
format(string,128,"%s",ConvertSecondsIntoMinute(TimeLeft));
TextDrawSetString(tTimeLeft,string);
ConvertSecondsToMinutes(seconds)
{
new
minutes,
output[ 8 ]; //8 cells. This allows the maximum output to be XXXX:XX - I don't think you will exceed 9999 minutes and 59 seconds.
while( seconds > 60 )
{
minutes ++;
seconds -= 60;
}
format( output, sizeof( output ), "%02i:%02i", minutes, seconds );
return output;
}
print( ConvertSecondsToMinutes( 323 ));
05:23
[20:22:13] Time taken to execute My SecToMS: 1066ms [20:22:45] Time taken to execute LarzI's SecToMS: 31218ms
#define FILTERSCRIPT
#include <a_samp>
public OnFilterScriptInit() {
new f_Tick, l_Tick;
f_Tick = GetTickCount();
for (new d; d < 1000000; d++)
SecondsToMinutesSeconds(54684);
l_Tick = GetTickCount() - f_Tick;
printf("Time taken to execute my SecToMS: %dms", l_Tick);
f_Tick=0; l_Tick=0;
f_Tick = GetTickCount();
for (new d; d < 1000000; d++)
ConvertSecondsToMinutes(54684);
l_Tick = GetTickCount() - f_Tick;
printf("Time taken to execute LarzI's SecToMS: %dms", l_Tick);
f_Tick=0; l_Tick=0;
return 1;
}
stock SecondsToMinutesSeconds(seconds)
{
new mins, sec;
mins = seconds/60; // Divide by 60 to get minutes
sec = seconds%60; // Modulo 60 gets the remainder of a division, meaning the left-over seconds.
new string[12];
format(string, 12, "%d:%02d", mins, sec);
return string;
}
stock ConvertSecondsToMinutes(seconds)
{
new
minutes,
output[ 8 ]; //8 cells. This allows the maximum output to be XXXX:XX - I don't think you will exceed 9999 minutes and 59 seconds.
while( seconds > 60 )
{
minutes ++;
seconds -= 60;
}
format( output, sizeof( output ), "%02i:%02i", minutes, seconds );
return output;
}
|
I wouldn't go with the "while" loop. It's uber slow. Don't know if it's a side-efect of using a for-loop with while. But I benchmarked your code and my own simplest version without loops and results were shocking.
Код:
[20:22:13] Time taken to execute My SecToMS: 1066ms [20:22:45] Time taken to execute LarzI's SecToMS: 31218ms pawn Код:
|