The Accessibility Inspector comes with a color contrast calculator. Use the shortcut Option Command C to open it.