Skip to content
Test script to emulate a relatively heavy workload for battery life testing.
Shell
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore Initial revision of script and finalized README. Jan 7, 2017
LICENSE Initial commit Jan 7, 2017
README.md Fixes #8: Add note about non-macOS platforms. Jan 11, 2017
battery-test.sh add battery capacity detection for linux Jan 10, 2017

README.md

MacBook Pro Battery Life Test

This repository contains a simple test script to emulate a relatively heavy workload for battery life testing. It downloads a copy of Drupal VM and repeatedly builds and destroys a Virtual Machine running Drupal.

The script does the following, in a loop:

  1. Write a counter, timestamp and the battery percentage (as reported by pmset) to a results file.
  2. Run vagrant up to configure a VM running Drupal on a standard LAMP stack.
  3. Run vagrant destroy -f to destroy the VM.
  4. Wait 10s.
  5. Repeat.

To run the script, you should already have the latest versions of Vagrant and VirtualBox installed.

Note about Vagrant plugins: The author runs the tests without vagrant-cachier installed for consistency's sake. If you use Vagrant regularly, check to make sure you don't have any plugins installed which could affect the consistency of this test using vagrant plugin list!

Other Platforms

This test script should run on any platform which supports Vagrant and VirtualBox, though it's only been tested on macOS, Fedora, and Ubuntu at this time.

Usage

Before running the test script

  1. Disable Sleep: Go to System Preferences > Energy Saver, click on the 'Battery' tab, and drag the 'Turn display off after' slider all the way to 'Never' (alternatively, you could run caffeinate in a separate Terminal window).
  2. Disable Screen Saver: Open System Preferences > Desktop & Screen Saver, then set the Screen Saver to 'Start after: Never'.
  3. Turn up brightness: For consistency's sake, turn up your screen brightness all the way (after the AC power has been disconnected).
  4. Quit all other Applications: To make it a fair comparison. (I also make sure all my Macs are running identical software configurations using the Mac Development Ansible Playbook).

Run the test script

  1. Download project: Download this project to your computer (either download through GitHub or clone it with Git). Important Note: Don't download the project in a 'cloud' directory (e.g. inside Dropbox, Google Drive, or a folder synced via iCloud).
  2. Open Terminal (full screen): Open Terminal.app and put it in full screen mode (so the actual pixels displayed is identical from laptop-to-laptop).
  3. Run Script: Change into this project's directory (cd path/to/macbook-pro-battery-test). Run ./battery-test.sh, and then walk away for a few hours.

After your Mac forces a sleep (when the battery has run out), plug it back in, then check the most recent file in results/ in the project directory.

Results

Results are written to a date-and-timestamped file inside the results folder. This file is in CSV format, so you can open it in Excel, Numbers, Google Sheets, or any other CSV-compatible program and graph the results as needed.

The results file has the following structure (as an example):

Counter Time Battery Percentage
0 2017-01-07 15:58:40 100%
0 2017-01-07 16:10:48 98%
0 2017-01-07 16:17:22 94%
... ... ...

Results of this script's test runs have been posted to the author's blog and a public Google Sheet:

Author

This script was created by Jeff Geerling to run some more formal battery tests on the 2016 Retina MacBook Pro—both with and without Touch Bar—and to see if battery life and performance between the two models (under heavier load) was much different.

You can’t perform that action at this time.