Young adults who watch a lot of TV and don't exercise much may start to see the effects of their unhealthy habits on their brains as early as midlife, a new study suggests.

In the study, researchers looked at the TV viewing habits of more than 3,200 people, who were 25 years old, on average, at the start of the study. The people in the study who watched more than 3 hours of TV per day on average over the next 25 years were more likely to perform poorly on certain cognitive tests, compared with people who watched little TV, the researchers found.

The results suggest that engaging in physical activity, as opposed to sitting and watching TV, is important for brain health, said study author Tina D. Hoang, of the Northern California Institute for Research and Education at the Veterans Affairs Medical Center in San Francisco. "Being physically active at any time in your life is good for your brain," Hoang said.

In the study, the researchers asked the participants every five years how many hours per day they spent watching TV on average during the past year. At the start of the study, and again every two to five years later, the researchers asked the participants if, and how much, they exercised. [6 Foods That Are Good For Your Brain]

After the 25 years, the researchers also examined the people's cognitive function using three tests that assessed the speed at which they processed information, their verbal memory and executive function — a number of mental skills that help people plan, organize and pay attention.

The 353 people in the study who watched more than 3 hours of TV per day, on average, were more likely to perform worse on some of the tests, compared with people who watched little TV, the researchers found.

And the 528 people in the study who exercised the least performed worse on one of the tests than the people who were more physically active, the researchers found.

In addition, the 107 people in the study who both exercised the least and watched more than 3 hours of TV per day were twice as likely to perform poorly on the cognitive tests, compared with those who spent little time watching TV but exercised more.

It is not clear exactly why spending more time watching TV may be linked to worse cognitive performance later in life. One hypothesis is that television viewing is not a cognitively engaging way of spending time, Hoang said.

Or it could be that people who watch a lot of TV and don't exercise much may have other unhealthy lifestyle habits, such as a poor diet, which might also contribute to their worse cognitive function, she said.

The new study was published today (Dec. 2) in the journal JAMA Psychiatry.

Copyright 2015 LiveScience, a Purch company. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.