Biodiversity and habitat destruction: a comparative study of model forest and coral reef ecosystems