A characterization technique is discussed that allows quantitative optimization of doping in epitaxially grown semiconductors. This technique uses relative changes in the host atom secondary ion (HASI) energy distribution from secondary ion mass spectroscopy (SIMS) to indicate relative changes in conductivity of the material. Since SIMS is a destructive process due to sputtering through a film, a depth profile of the energy distribution of sputtered HASIs in a matrix will contain information on the conductivity of the layers of the film as a function of depth. This process is demonstrated with Mg-doped GaN, with the Mg flux slowly increased through the film. Three distinct regions of conductivity were observed: one with Mg concentration high enough to cause compensation and thus high resistivity, a second with moderate Mg concentration and low resistivity, and a third with little to no Mg doping, causing high resistivity due to the lack of free carriers. During SIMS analysis of the first region, the energy distributions of sputtered Ga HASIs were fairly uniform and unchanging for a Mg flux above the saturation, or compensation, limit. For the second region, the Ga HASI energy distributions shifted and went through a region of inconsistent energy distributions for Mg flux slightly below the critical flux for saturation, or compensation. Finally, for the third region, the Ga HASI energy distributions then settled back into another fairly unchanging, uniform pattern. These three distinct regions were analyzed further through growth of Mg-doped step profiles and bulk growth of material at representative Mg fluxes. The materials grown at the two unchanging, uniform regions of the energy distributions yielded highly resistive material due to too high of Mg concentration and low to no Mg concentration, respectively. However, material grown in the transient energy distribution region with Mg concentration between that of the two highly resistive regions yielded low resistiv- ity (0.59Ωcm) and highly p-type (1.2×1018cm-3 holes) Mg-doped GaN.