How to know if your code is executed on wordpress.com and wordpress.org?

You can try to identify a custom plugin or combination of plugin found on wordpress.com (check the code of https://wordpress.org/plugins/list-plugins/) and defined if you are self-hosted or not.