Don't look now, but Wal-Mart's (WMT 0.46%) online sales grew faster than Amazon.com's (AMZN -2.56%) last quarter. Wal-Mart reported a 63% increase in U.S. online sales last quarter, while Amazon managed just 24% growth year over year.

Many point to Wal-Mart's acquisitions of Jet.com, Modcloth, Moosejaw, Shoebuy, and several other small e-tailers as the basis for its growth. But management says the majority of the growth stems from Walmart.com.

Of course, most of Wal-Mart's sales come from its physical stores. Wal-Mart's total revenue increased just 1.4% in the first quarter but was more than three times as much as Amazon's. Meanwhile, Amazon has a market cap nearly twice as much as Wal-Mart's. So which makes a better buy for investors?

Wal-Mart boxes coming down a conveyor belt

Image source: Wal-Mart

Wal-Mart is suddenly all about e-commerce

Online shopping is an undeniable megatrend. E-commerce sales in the U.S. increased nearly 15% last quarter while brick-and-mortar sales increased less than 3%, just slightly faster than inflation. If Wal-Mart expects to grow sales, it needs to compete online.

To that end, the company is investing heavily in new e-commerce initiatives. Not only is it buying up smaller e-commerce businesses, but it's also overhauling Walmart.com. The website now has 50 million items available for sale through its own stores and third-party merchants, up from 10 million at this time last year. At the beginning of the year, the company introduced free two-day shipping on over 2 million items for orders over $35. It's also looking for ways to leverage its physical stores -- offering discounts for picking up online orders in stores and using in-store employees to ship orders the last mile as they leave stores after their shifts.

The efforts are starting to pay off, as seen in its first-quarter earnings results. But Wal-Mart is still well behind Amazon in the e-commerce space. Amazon is a much bigger threat to Wal-Mart's cash-cow brick-and-mortar business than Wal-Mart is to Amazon's online business.

A worker holds an Amazon box as others come down a conveyor belt.

Image source: Amazon.com.

Amazon is all about Prime

Amazon Prime is one of the biggest driving forces behind the company's retail sales growth. Prime members are generally more loyal and spend more on Amazon, and their numbers are growing like crazy. By the end of the first quarter, Amazon had an estimated 80 million Prime members in the U.S. alone. That's double the number it had two years prior.

Amazon has taken steps to make it easier for customers to become Prime members. It introduced monthly pricing last year, so customers didn't have to pay $99 upfront. Most recently, it started offering a discount for customers on government assistance. That move is aimed directly at Wal-Mart, which caters to more low-income households.

Wal-Mart has tried to compete with Prime in the past. Its ShippingPass failed to catch on before it scrapped the project for free shipping earlier this year. Even now, Wal-Mart only offers free two-day shipping on 2 million items on its website, whereas Prime guarantees two-day shipping on over 50 million items on Amazon.com.

And even as Wal-Mart uses its heft as the world's largest retailer to put pressure on suppliers and reduce prices, Amazon isn't afraid to slash its prices to win customers. Amazon is willing to forgo profits today for a bigger piece of the pie tomorrow.

So which is worth buying?

Although Amazon is executing on all fronts, its four-figure share price may scare off potential investors. Any way you look at it, Amazon is a much more expensive stock than Wal-Mart.

While Amazon is successfully fending off Wal-Mart's e-commerce attacks, it's important to remember that e-commerce is still only a small part of retail. While online may account for the majority of growth, over 90% of sales in the U.S. happen in physical stores. Importantly, U.S. Census Bureau data indicates that those sales are steadily climbing slightly faster than inflation. In other words, Wal-Mart is set up to produce steady cash flows for investors through its thousands of physical stores for many years.

Investors looking for that kind of stability, with a nice dividend payment to boot, may be well served by Wal-Mart.

But if you're looking to invest in the growth of e-commerce, you will be better off with Amazon. Despite Wal-Mart's recent efforts, Amazon is very much at the forefront of e-commerce, and the competition isn't even close. It has numerous long-term advantages -- most importantly a growing Prime membership base -- that will allow it to continue gaining share in e-commerce, providing rapid revenue growth despite its relatively large size. What's more, the company has shown a willingness to enter new markets (such as cloud computing and consumer electronic devices) with significant sales potential to supplement its core retail business.

Investors willing to pay a premium for growth will find few companies in a better position than Amazon.