performance of the swtich/case statements

bycn82 bycn82 at gmail.com
Wed Oct 29 14:39:37 UTC 2014


Hi All,

 

It is using the switch/case statement to make the code clear in the
implementation, so it reminded me the question which I want to ask when I
read the source of ipfw for the first time. It is about the performance of
the switch/case statement. Sure the code of this table feature are running
in the user-land, so there is no performance concern here, But my question
is the switch/case statements in the 2 loops.

 

I am not a C programmer, so I am not clear how the switch/case will be
optimized by the compiler in FreeBSD. But I used to write a compiler by
myself and I use a hash table to handle all the conditions in the case
statements because my compiler don't care about performance!, But in C it is
different, the case statement can only accept "int" values, so I don't think
it will use hash or what , it should be directly use an array(), So whether
it can be optimized it depends on the conditions in the switch/case
statements, and I noticed that the cases statement in the 2 loops are not
arranging the opcode in running number, so does the compiler smart enough to
optimize it?

 

Regards,

Bycn82

 

From: bycn82 [mailto:bycn82 at gmail.com] 
Sent: Wednesday, 29 October, 2014 10:17 PM
To: 'freebsd-ipfw at freebsd.org'
Subject: ipfw table features

 

Hi,

Finally got some time to read the new implementation of table feature.
Compare to the previous code, it is much more clear now, Well done!

 

Regards,

Bycn82



More information about the freebsd-ipfw mailing list