On the iMac, System preferences/Power saving, move the slider for "Computer sleep" all the way to the right for "Never" and then set the "Display sleep" for whatever you want. Those settings will keep the CPU running enough to sustain a WiFi connection continuously. There is a "heartbeat" check on WiFi that a sleeping computer doesn't respond to, so the router thinks it's gone away and checks it out. On wakeup, the connection is broken, and what you are seeing is the delay while the iMac renegotiates with the router.