Image source: eBay.

There's no doubt that e-commerce is wreaking havoc on the sales of brick-and-mortar retailers. As more consumers do more of their shopping online, several companies stand to benefit from the trend. Chief among them are Amazon.com (AMZN 3.65%) and eBay (EBAY 1.23%).

Both companies have seen their stock prices climb considerably over the past year. Amazon's share price is up 58% and eBay stock is up 26%. Is Amazon getting ahead of itself -- making eBay a comparatively better buy right now -- or is its ever-growing stock price well-deserved? Let's take a closer look at these two e-commerce leaders to find out.

Getting people to shop more

eBay may have been a pioneer in online shopping, but it's struggled recently to grow sales on its properties. Gross merchandise volume grew just 9% in 2014, but declined 1% last year. Through the first half of 2016, gross merchandise volume in its marketplace business is up just 1.6%.

By comparison, Amazon's sales are on fire. Net sales in the North America grew 23% in 2014 and 25% last year. Internationally, it saw more modest sales growth of 12% and 6% in 2014 and 2015, respectively. Through the first half of 2016, net sales are up 27% in North America and 27% internationally.

Amazon's strong sales growth, particularly in the United States, can be attributed to the success of Amazon Prime. The program has an estimated 49 million subscribers in the United States, according to Cowen & Co. analyst John Blackledge. By the end of the year, he expects half the households in the country to subscribe to Prime.

What's more, Prime members spend about two and a half times as much on Amazon.com compared to nonmembers. As the number of subscribers continues to climb, both in the U.S. and internationally, investors should expect Amazon's sales growth to continue for the foreseeable future.

eBay can't compete with Prime. The logistics of its site -- orders received and fulfilled almost entirely by third parties -- make guaranteeing fast shipping impossible. It experimented with such a system in Germany last year, but nothing has come of it.

Amazon's secondary business is also dominant

Both Amazon and eBay have secondary businesses outside of their main online marketplaces. eBay has StubHub and Amazon has Amazon Web Services (AWS), its cloud computing business.

StubHub is growing well this year after signing several contracts to become the primary marketplace for several teams, including the NBA's Philadelphia 76ers and Boston College Athletics. It also signed a deal this summer to become the official resale site for New York Yankees tickets.

StubHub sales have accelerated in each of the last three quarters, climbing 30%, 29%, and 35% year over year in the fourth quarter through second quarter, respectively. StubHub is also a much higher-margin business than eBay's main marketplace, which makes its growth even more valuable to the company.

Amazon, however, is seeing superior growth in its cloud computing business. After climbing 70% last year, AWS sales are up another 61% through the first half of 2016. Like StubHub, AWS also produces higher margins than the company's core business. The segment operating margin was 23.6% last year versus a consolidated operating margin of just 4.2%.

Notably, AWS already makes up a larger percentage of total sales at Amazon compared to StubHub's percentage of eBay's overall sales.

A look at valuation

It's clear Amazon is growing both its core and secondary businesses faster than eBay, but if the market is asking too high of a price, eBay could be a better buy.

On a price-to-earnings basis, Amazon stock trades for a ridiculous 206 times trailing earnings. Even using analysts' forward-looking estimates, Amazon trades for 142 times 2016 earnings expectations. eBay stock, by comparison, trades for less than 20 times its trailing earnings and less than 17 times analysts' 2016 earnings expectations.

Of course, analysts expect Amazon to grow a lot faster than eBay. AWS is quickly propelling the profitability of Amazon, and analysts expect its earnings to grow 50.6% per year over the next five years. eBay is only expected to grow earnings per share 5.7% annually over the next five years. With a growth rate nearly nine times faster, Amazon may well deserve a PE ratio nine times higher. It's pretty close.

Looking at free cash flow tells a similar story. Amazon's price-to-free-cash-flow ratio is about 54, while eBay trades for just 15 times its free cash flow over the trailing 12 months. But Amazon grew its free cash flow nearly 36% over the past year, while eBay saw free cash flow decline 37%. Over the past five years, Amazon's free cash flow nearly quintupled, and eBay's is up just 8%. Amazon deserves a much higher cash flow multiple than eBay.

Even though Amazon's share price has climbed to an all-time high recently, the stock still seems like a better buy than eBay based on its growth and relative valuation. It's worth noting, however, buying a company with such high expectations from analysts has the potential to be a much bumpier ride than a company with a much lower valuation and lower expectations.