Skip to content

Instantly share code, notes, and snippets.

@jfriedly
Created August 28, 2014 02:10
Show Gist options
  • Save jfriedly/0da6b16f9c16bc5392d7 to your computer and use it in GitHub Desktop.
Save jfriedly/0da6b16f9c16bc5392d7 to your computer and use it in GitHub Desktop.
Use this script to demonstrate the effect of setting all CPUs on a machine to their maximum frequency
#! /usr/bin/python

import time


x = 0
last = time.time()

while True:
    x += 1
    if x % 10000 == 0:
        now = time.time()
        print now - last
        time.sleep(0.100)
        last = time.time()
@jfriedly
Copy link
Author

Use this script to demonstrate the effect of changing the Linux CPU governor from ondemand to performance. While the script is running, set all CPU governors to performance and watch the time drop!

Start by checking the frequencies of all your processors. Note that hyperthreads count as separate processors for this demonstration:

cat /proc/cpuinfo | grep "cpu MHz"

To set processors 0-7 to performance mode, use the command below (requires the cpufrequtils package).

for cpu in `seq 0 7`; do cpufreq-set --cpu $cpu --governor performance; done

Then watch the time for the script to hit 10000 each round, and check your processor frequencies again! The script will run faster and your frequencies will all be higher!

@jfriedly
Copy link
Author

Note to self: I think you can set the governors by echoing "performance" or "ondemand" to /sys/devices/system/cpu/cpuX/cpufreq/scaling_governor (replacing X with the CPU number). This way you don't have to install cpufrequtils.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment