Sex improves cognitive function by generating neurons in the hippocampus, where long-term memories are made. This is good news for those living with chronic stress, as sexual activity counteracts the negative affects of stress on brain development (Exercise and Prozac have the same effect).
Middle-aged rats who engaged in sexual behavior half an hour a day saw their brain function restored to young adult levels. Sexual activity also counteracts the negative affects of stress on brain development, thereby restoring neurogenesis.
However, the cognitive benefits to sex may require two to tango. Excessive pornography may damage the brain (though the research here is conflicted). Whether or not porn addiction literally damages the brain, it does negatively impact people’s short term, or “working memory”.