How to programmatically detect how many posts are displayed per page?

The option is appropriately named posts_per_page. FYI you can see the value of options in your database by visiting wp-admin/options.php.