This week the S&P 500 hit four-year highs, but all I can think of is the next bear market. No, it's not because I'm a negative guy who likes suffering and calamity, but because a bear market is inevitable. And there's no better time to get ready for the bad than when times are good.

No doubt the past four years were tough for investors. Well, at least the first two were. Of course, if you were dollar-cost averaging into your investments, things weren't nearly as bad. If you'd done that, your ride back up has likely been much more pleasurable than if you'd invested one lump sum four years ago and gone on autopilot.

So how can you best position your long-term portfolio for the next bear market? In trying to answer that question, I've been thinking a lot about the benefits of investing regularly over time, and also about the powerful effects of dividends.

Here at the Fool, we've pointed out more than once that an income investor has an advantage during a bear market, because the dividend yield helps create a floor for the share price. I think an even more important effect of dividends in a bear market is the reinvestment of the dividends into more shares. The effect is similar to dollar-cost averaging; the purchase of additional shares at low prices turbocharges your portfolio in the next recovery.

Still looks sweet
To set this in concrete in my mind, I decided to take a look at the performance of two companies since July 1998 (when I began investing) and compare it to the S&P 500, which has returned only 6.78% over that time frame. Starting my investing journey in the middle of 1998 with Starbucks (NASDAQ:SBUX), Qualcomm (NASDAQ:QCOM), General Electric (NYSE:GE), and an index fund put me in the market near the tail end of the greatest bull market ever. You could argue that I chose well; I'd argue I was lucky. I certainly was not thinking about dividends entering into a bear market.

To make the data analysis a bit easier -- or because I'm lazy -- I started with Wrigley (NYSE:WWY) because I have the data handy from a previous article about dividend reinvesting. Because that article used a longer time frame, I've stripped out the earlier data to reflect the time I started investing. It turns out that starting in July 1998 with $1,000 in Wrigley was about the worst time of the past few years that I could've chosen to start reinvesting in Wrigley shares. Despite being down the first couple of years, the returns still outpaced the 6.78% total returns of the S&P 500 (data from Yahoo! Finance) over the same time frame.

Date Price Shares Value Return
7/1/1998 49.38 20.26 1000.00 -
1/1/1999 43.53 20.46 890.62 -10.9%
1/1/2000 39.06 20.84 814.01 -18.6%
1/1/2001 46.19 21.20 979.12 -2.1%
1/1/2002 51.07 21.54 1100.05 10.0%
1/1/2003 56.60 21.86 1237.28 23.7%
1/1/2004 55.90 22.21 1241.54 24.2%
1/1/2005 68.04 22.54 1533.62 53.4%
Today 73.03 22.73 1659.97 66.0%

Along the way there was one stock split in Wrigley's shares (which is reflected in the data above). If dividends were stripped out of the equation and you go only by the gain in share price, the total return today is a less impressive but still solid 47.96%.

A totally different angle
The other company I decided to look at is a real estate investment trust (REIT). I specifically chose this REIT because the share price didn't do much of anything the first two years. I also picked it because its attractively priced shares are the sort of thing Mathew Emmert might recommend to Motley Fool Income Investor subscribers. I also had a hunch that the sizable yield would make up for the initial poor performance of the shares. As you can see in the table below, my hunch was right -- $1,000 invested in Boston Properties (NYSE:BXP) crushed the S&P 500's 6.78% return over the same period.

Date Price Shares Value Return
7/1/1998 31.00 32.26 1000.00 -
12/28/1998 28.33 33.72 955.29 -4.5%
12/28/1999 29.68 35.69 1059.28 5.9%
12/27/2000 44.31 37.60 1666.06 66.6%
12/26/2001 38.32 39.84 1526.67 52.7%
12/26/2002 36.41 42.39 1543.42 54.3%
12/26/2003 48.34 44.88 2169.50 116.9%
12/29/2004 64.05 47.00 3010.35 201.0%
Today 73.03 47.99 3504.71 250.5%

The effect of dividend reinvesting is even more substantial here because the total returns without dividends reinvested -- again, considering only the gain in share price -- is a much lower but still impressive 135%. These data also point to the bull market that REIT shares have enjoyed in general the past few years. But the main point still stands: The effect of dividend reinvesting through a down or flat market is substantial.

Foolish final words
You're probably thinking: Well, that's two companies that pay dividends and have enjoyed market-smashing returns. No doubt, you might be thinking that had I picked Campbell's Soup (NYSE:CPB), the results would be quite different. To an extent that's true, because Campbell's shares are still below their 1998 level. However, I believe the effect of reinvesting dividends would narrow the return gap rather quickly, and if Campbell's rises again -- like Hershey Foods (NYSE:HSY) did after years of going nowhere -- shareholders receiving and reinvesting the dividends reap the greatest rewards.

Nathan Parmelee owns shares of Starbucks, but has no financial interest in any of the other companies mentioned in this article. You can view his profile here. The Motley Fool has an ironclad disclosure policy .