Over the past five years, the stock market has basically done nothing. The broad market, as measured by the Vanguard Total Stock Market ETF (NYSE: VTI), is up about 1%. But one sector you might not expect to have done well is construction machinery, which, while hurt by slowing infrastructure spending and homebuilding, has benefited from the strong market for agriculture and mining commodities. Let's take a look at which stocks in this sector look the best right now.

A varied playing field
Deere & Company Total Return Price Chart

Total Return Price Chart by YCharts

Two of the best-performing stocks represent the purest plays for the thesis -- Deere (NYSE: DE) is one of the biggest producers of agricultural machinery, and Joy Global (Nasdaq: JOYG) is one of the biggest producers of mining machinery. Other companies divide their focus, with Manitowoc (NYSE: MTW) being the most extreme example -- the company has two operating segments, one that makes cranes for construction, and the other that makes ice machines and refrigeration units for soda machines.

Deere & Company Revenues TTM Chart

Deere & Company Revenues TTM Chart by YCharts

Joy Global is the clear winner on sales, benefiting from the strong demand for things like coal, iron ore, and copper. AGCO (NYSE: AGCO) and Deere have also held up well, benefiting from strong international demand for tractors in agriculture.

You might expect Caterpillar (NYSE: CAT) to have done well for the same reason, but after selling its Challenger line to AGCO in 2002, it lacks certain crucial, agriculture-specific products, like combine harvesters and irrigation equipment.

Deere & Company Operating Margin TTM Chart

Deere & Company Operating Margin TTM Chart by YCharts

Revenue isn't everything, though, if a company has tight margins. The crown again goes to Joy Global, whose operating margins have consistently been nearly twice that of others.

However, they haven't really improved much over the last few years. Steady, high margins are great, but margin improvement can greatly leverage revenue growth, and it's been Deere and AGCO that have shown the most improvement. By widening its margins from 1.3% in 2006 to 6.6% in the  trailing 12 months, AGCO has leveraged modest revenue growth to massive net income growth.

Deere & Company Net Income TTM Chart

Deere & Company Net Income TTM Chart by YCharts

CNH Global (NYSE: CNH) has also shown gains in net income, but not from big revenue growth or larger operating margins. It's mainly because overall profit margins were already tight, and a smaller provision for restructuring costs and income taxes gave the company just enough extra basis points to represent a big increase.

Deere & Company Free Cash Flow TTM Chart

Deere & Company Free Cash Flow TTM Chart by YCharts

In the end, though, it's free cash flow that matters to most investors, and it's especially important in a capital-intensive business like this. The unlikely winner by a wide margin is Deere, trailed by Joy Global and CNH Global, but for very different reasons.

Deere leveraged modest revenue growth with operating-margin expansion and declining capital expenditures to grow free cash flow substantially. CNH did basically the same thing, but with accounting gimmicks rather than any impressive business improvement.

Joy Global really operated the best business, with substantial enough revenue growth to increase profits without needing wider margins than they already had. Capital expenditures were a drag on free cash flow, but they were necessary to grow the business and open more production capacity. Free cash flow is great because it means more profits are available for shareholders, but in some cases, you'd rather the company reinvest it for you, and Joy Global is one of those cases -- the company has averaged a 32% return on invested capital over the past five years. It's no wonder my colleague Jason Moser has tapped the stock for his Rising Star portfolio.

The Foolish bottom line
It's important not to be wowed by profit margin growth if it's not coming from actual business improvement. Deere and AGCO win for improving their business, but Joy Global certainly deserves attention for already having the best business, making it somewhat of a tossup between the three. Add these companies to My Watchlist to keep track of them.

This article represents the opinion of the writer, who may disagree with the “official” recommendation position of a Motley Fool premium advisory service. We’re motley! Questioning an investing thesis -- even one of our own -- helps us all think critically about investing and make decisions that help us become smarter, happier, and richer.