Investing isn't easy. Even Warren Buffett counsels that most investors should invest in a low-cost index like the S&P 500. That way, "you'll be buying into a wonderful industry, which in effect is all of American industry," he says.

But there are, of course, companies whose long-term fortunes differ substantially from the index. In this series, we look at how individual stocks have performed against the broad S&P 500.

Step on up, RLI (NYSE: RLI).                                                                   

RLI shares have crushed the S&P 500 over the last quarter-century, with most of the outperformance occurring in the last decade:

Source: S&P Capital IQ.

Since 1987, shares have returned an average of 14.7% a year, compared with 9.7% a year for the S&P (both include dividends). That difference adds up fast. One thousand dollars invested in the S&P in 1987 would be worth $19,200 today. In RLI, it'd be worth $80,300.                                                                                         

Dividends accounted for a lot of those gains. Compounded since 1987, dividends have made up about half of RLI's total returns. For the S&P, dividends account for 39% of total returns.

Now have a look at how RLI earnings compare with S&P 500 earnings:

Source: S&P Capital IQ.

Decent outperformance. Since 1995, RLI earnings per share have increased by 10.6% per year, compared with 6% a year for the broader index.

What has that meant for valuations? RLI has traded for an average of 16 times earnings since 1987 -- below the 24 times earnings of the broader S&P 500.

Through it all, shares have been strong performers over the last quarter-century.

Of course, the important question is whether that will continue. That's where you come in. Our CAPS community currently ranks RLI with a five-star rating (out of five). Care to disagree? Leave your thoughts in the comment section below, or add RLI to My Watchlist.