IBM (NYSE:IBM) and Oracle (NYSE:ORCL) are similar in many ways.

Both tech giants are weighed down by slow-growth legacy businesses, both are trying to generate fresh growth with new cloud services, and both face stiff competition from higher-growth rivals like Amazon (NASDAQ:AMZN) and Microsoft (NASDAQ:MSFT).

But over the past five years, IBM's stock has declined more than 20% as shares of Oracle have surged over 40%. Let's see why that happened, and whether or not Oracle will keep outperforming IBM over the next few years.

Metal bull and bear figurines.

Image source: Getty Images.

Similar struggles, similar solutions

IBM made some big mistakes under former CEO Sam Palmisano between 2002 and 2011. Instead of acquiring higher-growth cloud service companies, Palmisano focused on selling business units, cutting costs, and buying back stock to boost the company's EPS. Eventually, its revenue growth dried up as demand for its business software, hardware, and IT services waned.

Ginni Rometty, who succeeded Palmisano, initially maintained the same course. But then she started pursuing big acquisitions to grow IBM's cloud business, including the company's $2 billion takeover of SoftLayer in 2013 and the $34 billion takeover of Red Hat earlier this year. Rometty also dialed back buybacks to conserve cash.

Oracle was stuck in the same boat as IBM. Sales of its on-site database and business software products were fading, so it launched new cloud services and acquired more companies, including cloud-based enterprise resource planning (ERP) software maker NetSuite for $9.3 billion in 2016, and cloud-based construction project management service company Aconex for $1.2 billion in 2017.

Yet Oracle differed from IBM in one major way: IBM bought back fewer shares as it expanded its cloud businesses, but Oracle bought back more shares to boost its earnings. This strategy was controversial because it coincided with a deceleration in the growth of Oracle's cloud services -- which was then obfuscated by a change to the company's reporting segments that blended together its on-premise and cloud revenues.

Which company is growing faster?

IBM has struggled to post consistent revenue growth over the past few years due to the softness of its legacy businesses, competition in the cloud space, and brutal currency headwinds. Oracle faced the same headwinds, but it did a much better job growing its top line with the growth of its cloud services and acquisitions.

ORCL Revenue (TTM) Chart

ORCL Revenue (TTM) data by YCharts

IBM didn't provide revenue guidance for the full year, but Wall Street expects revenue (excluding the Red Hat acquisition) to dip 3%. That figure would also likely stay negative after adding Red Hat's revenue ($3.4 billion last year) into the second half of the year.

Oracle didn't offer exact guidance for its current fiscal year but stated that it would generate "faster" growth than its constant currency sales growth of 3% (flat as reported) in fiscal 2019. Analysts expect Oracle's reported revenue to rise 3% as it generates more sales from higher-growth services like Fusion HCM (human capital management) and NetSuite ERP.

Investors should note that IBM and Oracle are both growing their cloud businesses at much slower rates than Amazon and Microsoft. Amazon Web Services revenue rose 37% annually to $8.4 billion last quarter, while Microsoft's commercial cloud revenue (which include its cloud platform Azure, Office 365, Dynamics 365, and other services) jumped 39% to $11 billion.

How about earnings and valuations?

Oracle still relies heavily on buybacks, but tighter spending, layoffs, and restructuring efforts also significantly boosted its net income over the past three years. IBM struggled to grow its net income as it spent more money on investments and acquisitions, and throttled buybacks also resulted in inferior EPS growth.

ORCL Net Income (TTM) Chart

ORCL Net Income (TTM) data by YCharts

Oracle expects its full-year EPS to rise by double digits on a constant currency basis, and analysts expect 10% growth on a reported basis. IBM expects its adjusted EPS to rise by less than 1%, which matches Wall Street's expectations.

Oracle generates better revenue and earnings growth than IBM, but IBM's stock is cheaper, with a higher dividend yield. Oracle trades at 14 times forward earnings and pays a forward yield of 1.7%, while IBM has a forward P/E of 11 and a forward yield of 4.3%.

The winner: Oracle

Oracle is certainly guilty of buying earnings beats with buybacks, but it's still a better all-around investment than IBM. It has better growth, its business has slightly fewer moving parts, and its stock looks reasonably cheap relative to its growth. Meanwhile, I wouldn't touch IBM until it generates consistent revenue and earnings growth again.