Skip to content

Instantly share code, notes, and snippets.

│ intrinsics::move_val_init(&mut *dst, src) ▒
0.90 │ lea (%rsi,%rsi,4),%rcx ▒
0.05 │ shl $0x4,%rcx ▒
0.11 │ mov 0xb8(%rsp),%rdx ▒
0.80 │ mov %rdx,(%rax,%rcx,1) ▒
1.66 │ movaps 0xd0(%rsp),%xmm0 ▒
11.08 │ movups %xmm0,0x8(%rax,%rcx,1)

My approach:

  • Let's use "cost" as a proxy for CO2 emissions, because within an order of magnitude I expect $1 on gas emits as much CO2 as $1 of power for a server, and I believe the bulk of the ongoing cost of operating a server is power budget.
  • Lifetime cost of a gas for a car: Let's estimate 100,000 miles, and 20 mpg and $4/gal. That gives us 5,000 gal and $20,000 in lifetime gas cost for a car. These numbers all feel pessimistic so we're maybe high.
  • A beefy server in AWS or GCP costs something like $1/hr, probably more for the really big ones. So in order to get to $20,000/run, we need 20,000 instance-hours. Let's ballpark a large training run at 1 day, so that's ~800 instances for one day. That feels within the realm of the numbers I've seen in papers.

Conclusion: Entirely plausible. Other conclusion: Lifetime cost of gasoline for a car is (in round numbers) the same as the cost of a new car. I hadn't realized they were so close. Other other conclusion: Now I understand why OpenAI needs billions o

@nelhage
nelhage / main.go.c
Last active September 22, 2020 02:49
A Go/C polyglot
// \
/*
#include <stdio.h>
int main() {
printf("Hello, World from C!\n");
return 0;
}
#if 0
//*/
https://www.dropbox.com
https://drive.google.com
https://aws.amazon.com
https://cloud.google.com
https://hangouts.google.com/
https://www.salesforce.com
https://www.bitfinex.com
https://www.coinbase.com/
https://gemini.com/
https://bitbucket.org
@nelhage
nelhage / float.cc
Last active February 6, 2019 15:42
#include <stdio.h>
#include <math.h>
#include <stdint.h>
static float rt(float x) {
volatile double g = static_cast<double>(x);
return static_cast<float>(g);
}
int main() {
#include <thread>
#include <experimental/optional>
#include <atomic>
#include <shared_mutex>
#include <mutex>
#include <iostream>
#include <vector>
using namespace std;
@nelhage
nelhage / README.md
Created April 26, 2018 03:14
Experience report: Trying to map an `FnMut` over a binary tree in Rust

This story is simplified from an attempt to write an AST walker for a toy compiler, but the essential facts are unchanged.

I am fairly new to Rust (but an experienced C++ programmer) and am trying to write a program to map an FnMut over a binary tree. I start with a simple tree definition, and try to write what seems to me to be the straightforward code:

use std::rc::Rc;
@nelhage
nelhage / cxx-move-semantics.cc
Created November 27, 2017 18:22
Which of these compile?
#include <memory>
using namespace std;
void accept_val(unique_ptr<int> i);
void accept_ref(unique_ptr<int> &i);
void accept_cref(const unique_ptr<int> &i);
void accept_rref(unique_ptr<int> &&i);
int main(int argc, char **argv) {
@nelhage
nelhage / acha_senate.txt
Created June 12, 2017 20:45
AHCA Senate Call Script
My name is Nelson Elhage. I'm a constituent of the Senator's in zip
code 94102.
I’m calling to express deep concern that Senate Republicans are
threatening to call for a vote on the ACA repeal without any public
hearings, and are keeping the text of the bill hidden from the public.
I urge the Senator to use every procedural tool at her disposal to
stop business as usual in the Senate and prevent this bill from
passing. I urge her to withhold consent when the bill comes to the
$ ruby -e 'puts ("".split(" ")).inspect'
[]
$ perl -MData::Dumper -E 'say Dumper([split(" ", "")])'
$VAR1 = [];
$ python -c 'print "".split(" ")'
['']
# https://play.golang.org/p/qErK71KCsF