The most important thing to remember when writing and optimizing a text is to make it reader-friendly. People will spot unnaturally "matched" keyword phrases instantly, so there's no point in measuring optimization by the exact number of keywords alone. Notably, this factor is not as important as it was in the 1990s when keyword stuffing was an extremely popular tactic.
Today, many SEO experts still adhere to some reasonable rules and consider the optimum keyword density (the ratio of keywords to all words) on a given page to be 9-15%. Higher values could be considered spam (or keyword stuffing), and will likely do your site no good at all.
To calculate keyword density on a Web page, simply use the formula:
(Nkr / Tkn) * 100,
where Nkr is the number of times a keyword is used, and Tkn represents the total number of words in the analyzed text.
If you need to calculate the density of a keyword phrase, use the formula (Nkr * Nwp / Tkn) * 100, where Nwp is the number of words in the phrase.
For example, the density of the keyword "keywords" on this page is (10/378*100 or 2.64%). Likewise, the density for the phrase "search engines" is (2*2/378)*100 or 1.05%).
As an alternative to counting these manually, you can use the Web CEO Optimization feature. This tool calculates various keyword-related scores, such as density (or weight(, frequency, prominence, etc.