performance - Checking perfomance between if(false){}else{if(false){}} and if(false){}else if(false){} -
please checking performance between 2 block code bellow. can't think both same when run-time(overlook figure element , same condition).
// block if(condition1) { // } else { if(condition2) { // } else { if(condition3) { // } else { if(condition4) { // } } } } //-------------------------------- // block ii if(condition1) { // } else if(condition2) { // } else if(condition3) { // } else if(condition4) { // }
help me!
assuming language c (you didn't specify), can verify 2 snippets generate exactly same code comparing assembly output of gcc:
#!/bin/bash diff <(gcc -o0 -s -o - -x c - <<eof extern int condition1(); extern int condition2(); extern int condition3(); extern int condition4(); extern void do_something1(); extern void do_something2(); extern void do_something3(); extern void do_something4(); void main() { if(condition1()) { do_something1(); } else { if(condition2()) { do_something2(); } else { if(condition3()) { do_something3(); } else { if(condition4()) { do_something4(); } } } } } eof ) <( gcc -o0 -s -o - -x c - <<eof extern int condition1(); extern int condition2(); extern int condition3(); extern int condition4(); extern void do_something1(); extern void do_something2(); extern void do_something3(); extern void do_something4(); void main() { if(condition1()) { do_something1(); } else if(condition2()) { do_something2(); } else if(condition3()) { do_something3(); } else if(condition4()) { do_something4(); } } eof )
this generates no output (you can prove test valid (e.g.) removing last condition 1 of functions , observing shows difference).
since assembly language output identical 2 blocks, can deduce performance characteristics must same.
Comments
Post a Comment