Companies with this trait are blowing away the S&P

Investors look at a lot of factors when buying stocks: a company's guidance, cash flow, price-to-earnings ratio. Those numbers are based on quantifiable facts (or they're supposed to be). But what about ephemeral factors, like employee satisfaction? How much does it matter, and can it be measured?

Employees celebrate opening of Apple store in Rio de Janiero, Brazil
Getty Images
Employees celebrate opening of Apple store in Rio de Janiero, Brazil

It turns out that it can be measured, and it apparently matters a lot. Companies with happy workers can outperform the broader market handily, while companies with less-than-happy employees see shares fall short.

Glassdoor, a website where employees rate their own companies, is promoting those reviews as a useful tool for investors. It has released an analysis of the share performance over five years of the highest-rated companies on its website, as well as those companies listed by Fortune as the best companies to work for. Investors who bought shares in companies on both lists saw stock gains that were much better than the S&P 500's—in some cases twice as good.

"Like any financial asset, a satisfied and engaged workforce is a highly valuable attribute of companies," said Andrew Chamberlain, Glassdoor's chief economist.

Read MoreA great jobs report for waitstaff and bartenders

For example, anyone who bought shares in all 36 companies listed on Glassdoor's Best Places to Work list in 2009 and held those shares through the end of 2014 had returns topping 236 percent, twice as good as the S&P's performance during the period. Those buying shares in Fortune's list of the Best Companies to Work For in 2009 also tripled their money over five years.

Both lists have several companies in common, like Adobe, Cisco Systems, Genentech, General Mills, Goldman Sachs, Google, Marriott, Nordstrom, and Whole Foods. But the two lists also diverge, and not all of them have been winners. On Glassdoor's list there's Apple, Best Buy, Lockheed Martin, Nike, and Netflix, while on the Fortune list there's Aflac, Build-A-Bear, DreamWorks Animation and Starbucks.

Glassdoor also looked at what would happen if investors swapped out portfolios each year as its new list came out. The rebalanced portfolio over five years had gains of 219 percent. Also, investing in only the five companies that have appeared on the list every year—Apple, Chevron, Google, National Instruments and Qualcomm--brought gains of 180 percent, still better than the S&P's 121 percent growth over those five years.

The report found even a short term bump after companies were named to the Glassdoor list, as shares jumped on average 0.75 percent in the 10 days that followed.

Of course, it's in Glassdoor's interest to promote the usefulness of its ratings, and those who write reviews on the site do so anonymously, with no proof they are the employees they claim to be. But the stock returns speak for themselves. Those are cold, hard facts.

"Although this analysis cannot establish a causal relationship between employee satisfaction and stock returns," the report concludes, "it clearly suggests the value of employee company reviews as a meaningful predictive behavior of financial performance."

Read MoreVodafone launches new policy for working moms

There was one year where those Glassdoor portfolios underperformed the broader market—2011. That year, the market as a whole was flat, while the portfolios of Glassdoor's best companies to work for all lost ground. Also, from 2012-2014, the portfolio containing only the five firms that have always made the list underperformed the S&P, offsetting strong outperformance earlier. Apple in particular had drastic swings during that time.

On the other hand, what about firms receiving low ratings from employee reviews in Glassdoor? Investors still made money in those firms from 2009-2014, with gains of 92 percent, but that was not as good as investing in the broader market.