mosdepth is a command-line tool for fast depth calculation. Because of the underlying algorithm it is possible to build a lot of features around the calculation. For example, once depth is calculated for every base in a chromosome, mosdepth can calculate the mean coverage in each of 100K intervals in about 1 additional second total. There are a number of additional features such that, for the most part, users can get all depth information out of a BAM/CRAM in a single pass.
You can read about it here in the bioinformatics app note.
and get the code and binary on github here
The github page describes the options and usage in more detail.