DefineTest.amxx
PHP Code:
#define MYSTRING1 "MyString1"
#define MYSTRING2 "MyString2"
#define MYSTRING3 "MyString3"
#define MYSTRING4 "MyString4"
#define MYSTRING5 "MyString5"
#define MYSTRING6 "MyString6"
#define MYSTRING7 "MyString7"
#define MYSTRING8 "MyString8"
#define MYSTRING9 "MyString9"
#define MYSTRING10 "MyString10"
ConstTest.amxx
PHP Code:
new const MYSTRING1[] = "MyString1"
new const MYSTRING2[] = "MyString2"
new const MYSTRING3[] = "MyString3"
new const MYSTRING4[] = "MyString4"
new const MYSTRING5[] = "MyString5"
new const MYSTRING6[] = "MyString6"
new const MYSTRING7[] = "MyString7"
new const MYSTRING8[] = "MyString8"
new const MYSTRING9[] = "MyString9"
new const MYSTRING10[] = "MyString10"
PHP Code:
public plugin_init()
{
register_plugin("Test", "1.0", "")
new Str[33]
for(new i=0; i<100000; i++)
{
copy(Str, 32, MYSTRING1)
equal(Str, MYSTRING1)
format(Str, 32, "%s", MYSTRING1)
copy(Str, 32, MYSTRING2)
equal(Str, MYSTRING2)
format(Str, 32, "%s", MYSTRING2)
copy(Str, 32, MYSTRING3)
equal(Str, MYSTRING3)
format(Str, 32, "%s", MYSTRING3)
copy(Str, 32, MYSTRING4)
equal(Str, MYSTRING4)
format(Str, 32, "%s", MYSTRING4)
copy(Str, 32, MYSTRING5)
equal(Str, MYSTRING5)
format(Str, 32, "%s", MYSTRING5)
copy(Str, 32, MYSTRING6)
equal(Str, MYSTRING6)
format(Str, 32, "%s", MYSTRING6)
copy(Str, 32, MYSTRING7)
equal(Str, MYSTRING7)
format(Str, 32, "%s", MYSTRING7)
copy(Str, 32, MYSTRING8)
equal(Str, MYSTRING8)
format(Str, 32, "%s", MYSTRING8)
copy(Str, 32, MYSTRING9)
equal(Str, MYSTRING9)
format(Str, 32, "%s", MYSTRING9)
copy(Str, 32, MYSTRING10)
equal(Str, MYSTRING10)
format(Str, 32, "%s", MYSTRING10)
}
}
DefineTest.amxx
900 Bytes
Total time spent in string functions: 0.085721
Total time spent in plugin_init: 0.043563
Code:
date: Sat Aug 20 11:44:25 2016
type | name | calls | time / min / max
-------------------------------------------------------------------
n | register_plugin | 1 | 0.000000 / 0.000000 / 0.000000
n | copy | 10000 | 0.000243 / 0.000000 / 0.000014
n | equal | 10000 | 0.000246 / 0.000000 / 0.000017
n | format | 10000 | 0.000400 / 0.000000 / 0.000012
p | plugin_init | 1 | 0.000450 / 0.000450 / 0.000450
0 natives, 0 public callbacks, 1 function calls were not executed.
date: Sat Aug 20 11:44:55 2016
type | name | calls | time / min / max
-------------------------------------------------------------------
n | register_plugin | 1 | 0.000001 / 0.000001 / 0.000001
n | copy | 10000 | 0.000230 / 0.000000 / 0.000000
n | equal | 10000 | 0.000223 / 0.000000 / 0.000000
n | format | 10000 | 0.000380 / 0.000000 / 0.000000
p | plugin_init | 1 | 0.000421 / 0.000421 / 0.000421
0 natives, 0 public callbacks, 1 function calls were not executed.
date: Sat Aug 20 11:45:39 2016
type | name | calls | time / min / max
-------------------------------------------------------------------
n | register_plugin | 1 | 0.000000 / 0.000000 / 0.000000
n | copy | 10000 | 0.000227 / 0.000000 / 0.000000
n | equal | 10000 | 0.000223 / 0.000000 / 0.000000
n | format | 10000 | 0.000377 / 0.000000 / 0.000000
p | plugin_init | 1 | 0.000423 / 0.000423 / 0.000423
0 natives, 0 public callbacks, 1 function calls were not executed.
date: Sat Aug 20 11:46:21 2016
type | name | calls | time / min / max
-------------------------------------------------------------------
n | register_plugin | 1 | 0.000001 / 0.000001 / 0.000001
n | copy | 1000000 | 0.022548 / 0.000000 / 0.000001
n | equal | 1000000 | 0.022521 / 0.000000 / 0.000005
n | format | 1000000 | 0.038103 / 0.000000 / 0.000007
p | plugin_init | 1 | 0.042269 / 0.042269 / 0.042269
0 natives, 0 public callbacks, 1 function calls were not executed.
ConstTest.amxx
910 Bytes
Total time spent in string functions: 0.085711
Total time spent in plugin_init: 0.043791
Code:
date: Sat Aug 20 11:44:25 2016
type | name | calls | time / min / max
-------------------------------------------------------------------
n | register_plugin | 1 | 0.000004 / 0.000004 / 0.000004
n | copy | 10000 | 0.000221 / 0.000000 / 0.000000
n | equal | 10000 | 0.000227 / 0.000000 / 0.000001
n | format | 10000 | 0.000387 / 0.000000 / 0.000001
p | plugin_init | 1 | 0.000416 / 0.000416 / 0.000416
0 natives, 0 public callbacks, 1 function calls were not executed.
date: Sat Aug 20 11:44:55 2016
type | name | calls | time / min / max
-------------------------------------------------------------------
n | register_plugin | 1 | 0.000003 / 0.000003 / 0.000003
n | copy | 10000 | 0.000244 / 0.000000 / 0.000001
n | equal | 10000 | 0.000255 / 0.000000 / 0.000015
n | format | 10000 | 0.000404 / 0.000000 / 0.000001
p | plugin_init | 1 | 0.000512 / 0.000512 / 0.000512
0 natives, 0 public callbacks, 1 function calls were not executed.
date: Sat Aug 20 11:45:39 2016
type | name | calls | time / min / max
-------------------------------------------------------------------
n | register_plugin | 1 | 0.000004 / 0.000004 / 0.000004
n | copy | 10000 | 0.000242 / 0.000000 / 0.000000
n | equal | 10000 | 0.000221 / 0.000000 / 0.000000
n | format | 10000 | 0.000378 / 0.000000 / 0.000002
p | plugin_init | 1 | 0.000423 / 0.000423 / 0.000423
0 natives, 0 public callbacks, 1 function calls were not executed.
date: Sat Aug 20 11:46:21 2016
type | name | calls | time / min / max
-------------------------------------------------------------------
n | register_plugin | 1 | 0.000003 / 0.000003 / 0.000003
n | copy | 1000000 | 0.022563 / 0.000000 / 0.000001
n | equal | 1000000 | 0.022501 / 0.000000 / 0.000001
n | format | 1000000 | 0.038068 / 0.000000 / 0.000004
p | plugin_init | 1 | 0.042440 / 0.042440 / 0.042440
0 natives, 0 public callbacks, 1 function calls were not executed.
The only issue is that the original conclusions drawn by the topic seemed to be "only use #define if you think you'll only use the reference once, otherwise a constant is always better", and then sort of belittled and commanded people to go make good code by using only constants.
The real answer is it doesn't matter and everyone should write in a way that they find easiest to read and maintain. That should be the #1 goal for everyone, not splitting hairs over whether or not someone might judge you for preferring to use #define over constants.
__________________