It's been nothing short of a banner year for both FireEye (MNDT) and Fortinet (FTNT -0.97%), with the data security providers' stocks climbing 20% and 25%, respectively, in 2017. Investor optimism is well founded, but for different reasons.

FireEye CEO Kevin Mandia is in the midst of sweeping changes that have already positioned it for the better. Fortinet hasn't had to reinvent itself entirely, but rather tweak a few key areas that are also beginning to pay off in a big way.

So which is the better buy? For investors who prefer stocks with a rock-solid foundation to drive future growth, one has a distinct advantage.

Image of a digitized planet Earth with a key in the center.

Image source: Getty Images.

The case for FireEye

When a new CEO takes the reins of a struggling company with meager revenue growth and out-of-control spending, as Mandia did last summer, talk about becoming a more efficiently run organization is often par for the course. But FireEye has made impressive strides with each successive quarter, proving that Mandia and team are doing a lot more than just talking the talk.

Last quarter was yet another in a string of earnings reports in which FireEye not only pleasantly surprised on its top line, but the promised cost-cutting continued. Operating expenses were shaved 24% compared to a year ago, which has already become a common theme with every passing quarter. A particular area of focus has been sales-related costs, which FireEye is addressing in a couple ways.

First, Mandia immediately cut FireEye's sales force and promised more expense-focused realignments would follow. FireEye still spent $89.6 million on sales and marketing last quarter, nearly half its revenue of $185.47 million which was a 6% improvement. However, sales-related overhead in FireEye's second quarter was a 26%d decline year over year.

Another key initiative of FireEye's is to grow its subscription-based cloud software sales to build a lower-cost, predictable foundation of recurring revenue. Again, FireEye is delivering in a big way. Last quarter's 15% jump in subscription revenue to $154.3 million more than compensated for the 23% drop in product sales to $31.2 million. Profitability is still an objective, but FireEye continues to inch closer every quarter.

The case for Fortinet

Like FireEye, Fortinet not only handily beat expectations in its second quarter, but also raised guidance for the current quarter and the balance of 2017 after reporting a 17% rise in revenue to $363.5 million. Fortinet is also delivering on the bottom line, reporting a stellar $0.13-per-share profit compared to a $0.01 loss a year ago.

Also similar to FireEye and most of its peers, Fortinet CEO Ken Xie is laser-focused on growing predictable subscription revenues, and last quarter was yet another successful example. Though operating expenses did rise to $239.3 million, that was a mere 3.6% increase year over year which is more than tolerable given Fortinet's top-line results.

Though product sales rose 4% in the second quarter, it was the whopping 26% jump in service-oriented recurring revenue to $220.8 million -- equal to 60% of total sales -- that drove Fortinet's surprisingly strong growth. With Fortinet's deferred revenue climbing 28% to $1.16 billion in the quarter, it's safe to say its growing revenue base will continue.

The envelope, please

As you may have gathered, I'm an unabashed bull for both FireEye and Fortinet stock, and investors have a slew of reasons to feel likewise. But when it's said and done, the strength of Fortinet's fundamentals -- growing both the top and bottom lines while maintaining a grip on spending -- wins the day, which is why it narrowly edges FireEye as the better buy.