The new Will Ferrell cop comedy, “The Other Guys,” is good. But it would have been great without Ferrell. His untethered performance beats the comedy life out of most of his scenes.

Ferrell plays Allen Gamble, a numbers-crunching New York detective content to sit at his desk. Terry Hoitz (Mark Wahlberg), who’s been partnered with Gamble as a punishment for shooting a sports legend, desperately wants to get into the streets and stop some real criminals.

He gets his chance to be a hero when a routine case turns into a major crime. (I know, this sounds a lot like the lame Fox TV series “The Good Guys” but they really are two different projects.)

Along with Ferrell, the cast includes funny men Michael Keaton and Steve Coogan. Yet it’s singer-turned-actor Wahlberg who’s the best part of the movie. He shows a great sense of timing and a fearlessness to play against his tough-guy roles in movies such as “The Departed.” That even includes a few ballet moves.

In one scene, Gamble introduces Hoitz to his “rather plain wife” Sheila, played by the very attractive Eva Mendes. Wahlberg’s reactions to Sheila are perfectly funny.

Even Samuel L. Jackson and Dwayne Johnson, as the super cops Gamble and Hoitz aspire to be, are hilarious (they would have made a great movie on their own).

Ferrell, whose career has spiraled down through flops like “Semi-Pro” and “Land of the Lost,” seems to have decided the best way to be funny is to shout. In “The Other Guy” he constantly slips into insane rants that eclipse the real humor in the film.

McKay and Chris Henchy have written a script that takes some very funny jabs at the buddy-cop genre. That it provides plenty of laughs despite Ferrell’s rants shows just how good it is. But the best script can’t overcome a bad performance.