ID:151273
 
what way is better to convert num 2 text in this case?


this

health_hud.icon_state = "[src.hp]" // hp is a num var


or this?

health_hud.icon_state = num2text(src.hp)


thanks.
This is such a simple operation that the difference, if there is one, is probably negligible. When you consider how fast either operation is and how many times it would possibly be called, it won't make a noticeable difference.

Still, you can write a simple program to test this and see if there's a huge difference:

#define DEBUG
mob
verb
test1()
for(var/i = 1 to 10000)
var/a = "[rand(100)]"

test2()
for(var/i = 1 to 10000)
var/a = num2text(rand(100))


Compile the program, run it, and profile it (click on the DS window's icon, go to "Server", then "Profile..."). Click each verb a few times then click the "Refresh" button and compare the times.

When I ran it, num2text was slightly better: the test2() verb took 0.883 seconds for 10 calls, test1 took 0.908 seconds for 10 calls. This means you can do "[n]" 110,000 times per second and num2text(n) 113,000 times per second. Considering you'll probably be calling these things 10-100 times per second, this is such a small fraction of your game's CPU usage that it doesn't really make a difference.
In response to Forum_account
thanks a lot. :)