Skip to content

Instantly share code, notes, and snippets.

@ChrisButterworth
Created August 16, 2022 14:37
Show Gist options
  • Save ChrisButterworth/f33315406215dc53f0114bcbd51e4129 to your computer and use it in GitHub Desktop.
Save ChrisButterworth/f33315406215dc53f0114bcbd51e4129 to your computer and use it in GitHub Desktop.
OneByte
export function OneByte(bytes: number, green: boolean): number {
const CO2_PER_KWH_IN_DC_GREY = 519;
const CO2_PER_KWH_NETWORK_GREY = 475;
const CO2_PER_KWH_IN_DC_GREEN = 50;
const KWH_PER_BYTE_IN_DC = 7.2e-11;
const FIXED_NETWORK_WIRED = 4.29e-10;
const FIXED_NETWORK_WIFI = 1.52e-10;
const FOUR_G_MOBILE = 8.84e-10;
// Using a simple mean for now - can amend
const KWH_PER_BYTE_FOR_NETWORK = (FIXED_NETWORK_WIRED + FIXED_NETWORK_WIFI + FOUR_G_MOBILE) / 3;
const KWH_PER_BYTE_FOR_DEVICES = 1.3e-10;
if (bytes < 1) {
return 0;
}
const device = bytes * CO2_PER_KWH_IN_DC_GREY * KWH_PER_BYTE_FOR_DEVICES;
if (green) {
// if we have a green datacentre, use the lower figure for renewable energy
const Co2ForDC = bytes * KWH_PER_BYTE_IN_DC * CO2_PER_KWH_IN_DC_GREEN;
// but for the rest of the internet, we can't easily check, so assume
// grey for now
const Co2forNetwork = bytes * KWH_PER_BYTE_FOR_NETWORK * CO2_PER_KWH_NETWORK_GREY;
return Co2ForDC + Co2forNetwork + device;
}
const KwHPerByte = KWH_PER_BYTE_IN_DC + KWH_PER_BYTE_FOR_NETWORK;
// return
return (bytes * KwHPerByte * CO2_PER_KWH_IN_DC_GREY) + device;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment