def measure_core_frequency(filename=None):
    """Returns the CPU frequency in MHz
    """
    if filename is not None:
        with open(filename, "r") as f:
            frequency = float(f.read()) / 1000
    else:
        # Only vcgencmd measure_clock arm is accurate on Raspberry Pi.
        # Per: https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=219358&start=25
        sys_freqfile=open("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq", "r")
        sys_freq =sys_freqfile.read()
        sys_freqfile.close()
        freq_int = int(sys_freq)
        frequency = freq_int / 1000
    return frequency