Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bd2720/ifswitch
https://github.com/bd2720/ifswitch
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/bd2720/ifswitch
- Owner: bd2720
- Created: 2024-05-13T20:39:41.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-05-15T02:08:55.000Z (8 months ago)
- Last Synced: 2024-05-15T20:08:06.924Z (8 months ago)
- Language: C
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.txt
Awesome Lists containing this project
README
Tests the efficacy of if-else statements vs. switch/case statements when
each branch has the same likelihood of occurring. if/else statements are
O(N), while switch should be O(1). So switch should be faster than if/else
at some value of N.COMPILATION:
$ makeRUN:
$ ./ifSwitchDESCRIPTION:
ifSwitch.h: defines the following adjustable constants:
ITERS : number of loop iterations for each test
N : number of equally-likely if-branches or switch-cases.if: generates the if macro, "if.out"
if.out: if/else macro with N cases, generated by "if"
switch: generates the switch macro, "switch.out"
switch.out: switch/default macro with N cases, generated by "switch"
ifSwitch: runs and times each macro, "if.out" and "switch.out"
OBSERVATIONS:
- For 2 <= N < 45, IF beats SWITCH by as much as 1.2x.
- For N ~ 45, IF and SWITCH run at about the same speed.
- For N > 45, IF is slower than SWITCH:
- For N ~ 195, SWITCH beats IF by 2x.
- For N ~ 1100, SWITCH beats IF by 10x.
- For IF and large N, (N * 2) runs for twice as long as (N).
- For SWITCH, (N * 10) will take 15% longer to run than (N).