E-commerce has been a boon for some companies, but has left many small businesses wondering how to adapt. Luckily for them, Square (SQ -1.68%) and Shopify (SHOP -2.37%) make it very simple and affordable for entrepreneurs and companies of all sizes to quickly adapt to consumers' increasing desire to use their mobile wallets at checkout and buy online. 

Both of these companies have experienced rapid growth in revenue and have delivered big gains for shareholders. But which is the better buy for investors today? Let's check it out.

A Square digital payment checkout system sitting on the checkout counter at a retail store.

Image source: Square.

The case for Square

Square has delivered impressive returns, with the stock skyrocketing 440% since its IPO in late 2015. Driving these gains has been growing demand for Square's services, spanning software features and point-of-sale checkout systems that make it painless for small businesses to quickly start accepting credit card payments either through mobile wallets or plastic cards.

Square operates like a payment processor, but with a twist. About three-quarters of Square's revenue is derived from transaction fees whenever someone buys something from a merchant that uses Square's digital registers or card readers.

Total revenue grew 30% in 2017, driven by growth in transaction fees. But other services, including software subscriptions (which make up 16% of total revenue), have been the company's fastest-growing category, up 131% year over year in the second quarter.

Driving this robust growth in subscriptions and services has been rapid adoption of Square's Cash App (peer-to-peer payments), which was the No. 1 finance app in the App Store last quarter. Other services, such as Square Capital (merchant loans), Square for Restaurants, and Caviar (an online food ordering/delivery platform), round out Square's ecosystem of offerings.

Rapid adoption of these services, in addition to acquisitions, has helped total revenue accelerate over the past five quarters. After a 30% increase on the top line in 2017, Square just reported a 48% year-over-year increase in the second quarter.

Square has been investing heavily in marketing and product development, which has made profits elusive. But it seems to have reached the tipping point lately, as rapid revenue growth lifted adjusted earnings to a positive $0.35 per share over the trailing-12-month period.

The case for Shopify

Because both companies are essentially serving the same need (creating a bridge for small businesses to the world of e-commerce), Shopify shares have performed equally well, up 468% since its IPO in 2015. But there are differences in how each company makes money.

While Square generates revenue primarily from transaction fees, Shopify's business is built more around subscription services (45% of revenue). For as little as $29 per month, merchants can access software tools, enabling them to set up and manage online storefronts, inventory, shipping, and data analytics.

The basic strategy is to first get a merchant signed up to a subscription plan, which can cost up to $2,000 per month for Shopify Plus, which is designed for large merchants. Once on a plan, Shopify can cross-sell other services, tightening the relationship between Shopify and the merchant. These services -- which make up 54% of revenue -- include cash advances (Shopify Capital), payments processing (Shopify Payments), and shipping solutions (Shopify Shipping).

Like Square, growth has been phenomenal. Since 2012, Shopify's revenue has climbed from as little as $24 million to $854 million over the trailing 12 months.

Recent growth has been very broadly based across subscriptions and merchant solutions. In the second quarter, subscription revenue grew at a robust rate of 55% year over year. But merchant solutions (or services) has been the company's fastest growing category, growing 68% year over year in the last quarter. This was driven by rapid adoption across Shopify Capital, Payments, and Shipping, reflecting just how valuable merchants find Shopify's platform.

Which is the better buy?

The addressable market for Square and Shopify is massive. For example, Square estimates its market opportunity at more than $70 billion, which is not far off Shopify's opportunity.

But this potential has certainly not gone unnoticed. These stocks are riding high, and neither has managed to generate enough profit to really justify their current market values, from my perspective.

Shopify has a $15.5 billion market cap, but hasn't generated a profit. Management's guidance only calls for adjusted operating income of $0 to $5 million this year, which would be roughly flat compared to 2017.

On the other side, Square generated $102 million in free cash flow last year (the first year that metric has been positive for the company), and management's guidance calls for adjusted earnings to grow 56% this year, assuming the company hits the low end of the range, between $0.42 to $0.46 per share. That still leaves Square trading for a nosebleed forward P/E ratio of about 160 -- a valuation that is hard to justify even with recent growth rates.

But if I had to choose one, I would go with the more profitable one. That leaves Square as the winner in this comparison.