Using my last example (I currently work on this "itteration" as I get the grip of it), without sleep I get 10000 ping-pongs every ~4 seconds. Using epiktimer systemsleep(1) I get 10000 every ~210 seconds.
Ok, I see what you mean.
But with your code, the 4 seconds for 10.000 ping pongs is also a lot of time without a sleep-line.
If I use my code I get this:
Without any sleep().
ip: 172.18.144.1
1 = send or 2 = listen? 2
ping from 192.168.2.11 0
1000 ping from 192.168.2.11 78
2000 ping from 192.168.2.11 78
3000 ping from 192.168.2.11 78
4000 ping from 192.168.2.11 62
5000 ping from 192.168.2.11 63
6000 ping from 192.168.2.11 62
7000 ping from 192.168.2.11 79
8000 ping from 192.168.2.11 93
9000 ping from 192.168.2.11 94
10000 ping from 192.168.2.11 78
11000 ping from 192.168.2.11 78
press enter to quit
So 765ms (0,7 seconds) for 10.000 ping pongs.
That's because my version uses the events and is much more efficient with the code flow.
Your code flow synchronous and also takes a lot of time with that flow itself (including waiting of the other side before sending another package).
Doing a sleep(0) didn't make much difference
ip: 172.18.144.1
1 = send or 2 = listen? 2
ping from 192.168.2.11 0
1000 ping from 192.168.2.11 78
2000 ping from 192.168.2.11 62
3000 ping from 192.168.2.11 63
4000 ping from 192.168.2.11 62
5000 ping from 192.168.2.11 78
6000 ping from 192.168.2.11 63
7000 ping from 192.168.2.11 62
8000 ping from 192.168.2.11 78
9000 ping from 192.168.2.11 63
10000 ping from 192.168.2.11 78
press enter to quit
Only when doing sleep(1) it got a lot slower.
ip: 172.18.144.1
1 = send or 2 = listen? 2
ping from 192.168.2.11 0
1000 ping from 192.168.2.11 29157
2000 ping from 192.168.2.11 29375
3000 ping from 192.168.2.11 29890
4000 ping from 192.168.2.11 30094
5000 ping from 192.168.2.11 30844
6000 ping from 192.168.2.11 30750
7000 ping from 192.168.2.11 31000
8000 ping from 192.168.2.11 30984
9000 ping from 192.168.2.11 30797
10000 ping from 192.168.2.11 30734
11000 ping from 192.168.2.11 30813
press enter to quit
BTW. With my event version the CPU doesn't go over the 25% (sometimes even far less) even without any sleep-line.
I think if you really want more control over performance you would need to go with Socket or Synapse sockets in threads.
But it all depends on what you want, where you use it for and what is practical.