Raised This Month: $37 Target: $400
 9% 

Which code is faster ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kellan123
AlliedModders Donor
Join Date: Aug 2012
Old 01-12-2019 , 18:43   Which code is faster ?
Reply With Quote #1

Which code is faster?

PrintToServer("%i", num > 1 ? 2 : num > 0 ? 1 : 0)

Or

Switch ( num )
Case 0: PrintToServer("0")
...
Kellan123 is offline
Headline
SourceMod Moderator
Join Date: Mar 2015
Old 01-12-2019 , 22:51   Re: Which code is faster ?
Reply With Quote #2

certainly the switch; but always go the most readable route (which also happens to be the switch in this specific case)
Headline is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 01-13-2019 , 12:52   Re: Which code is faster ?
Reply With Quote #3

Best practice is to use the switch but you canít go wrong either way. Print function is inexpensive unless you use it too frequently.
__________________
Spirit_12 is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:42.


Powered by vBulletin®
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Theme made by Freecode