Skip to content

Instantly share code, notes, and snippets.

View Spaceghost's full-sized avatar
👻
Building distributed and decentralized systems that run in the browser

Johnneylee Jack Rollins Spaceghost

👻
Building distributed and decentralized systems that run in the browser
View GitHub Profile

Benchmarking ruby

The problem: Create a hash from an array of objects where the key is the object's #id and the value is the #stuff method.

Known/Suspected caveats:

  • Garbage collection might be happening, making the results lie.
  • Not exhaustive of ways to create a hash from an array
  • Not exhaustive of ways to call Benchmark.ips with code to test. (no strings yet)
  • Not able to manually change the number of iterations
Calculating -------------------------------------
#inject assign&return
290.000 i/100ms
merge 1.000 i/100ms
merge! 106.000 i/100ms
each_with_object 292.000 i/100ms
zenspider 298.000 i/100ms
pipework 299.000 i/100ms
-------------------------------------------------
#inject assign&return

Benchmarking #map

#map(&:id) is faster than a block.
#map is faster than #each_with_object when doing roughly the same work.

In short, this might make you want to extract more public methods, even if you use them in decorators or proxy objects, that you can call with Symbol#to_proc.

require 'benchmark/ips'
User = Struct.new(:id, :stuff)
a = Array.new(1000) { |i| User.new(i, stuff: rand(1000)) }
Benchmark.ips do |x|
x.report('#inject assign&return') do
a.inject({}) { |memo, i| memo[i.id] = i.stuff; memo }
end
x.report('merge') do
@Spaceghost
Spaceghost / pr.md
Last active August 29, 2015 14:11 — forked from piscisaureus/pr.md

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@Spaceghost
Spaceghost / .README.md
Last active August 29, 2015 14:11 — forked from gnarf/..git-pr.md

Install

Either copy the aliases from the .gitconfig or run the commands in add-pr-alias.sh

Usage

Easily checkout local copies of pull requests from GitHub remotes:

  • git pr 4 - creates local branch pr/4 from the origin remote and checks it out
  • git pr 4 upstream - creates local branch pr/4 from upstream remote and checks it out
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.macports.gpg-agent</string>
<!-- Please uncomment on 10.4; OnDemand doesn't work properly there. -->
<!--
<key>OnDemand</key>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.gnupg.gpg-agent</string>
<key>ProgramArguments</key>
<array>
<string>start-gpg-agent</string>
tim0thy:phoenix-demo32 pipework$ java -jar phoenix_demo32.jar
Exception in thread "main" scala.MatchError: osx (of class java.lang.String)
at com.sg.pnx.util.SysUtil$.nativeLibs(SysUtil.scala:41)
at com.sg.pnx.util.SysUtil$.checkForNativeLibs(SysUtil.scala:88)
at com.sg.pnx.util.SysUtil$.loadNativeLibs(SysUtil.scala:80)
at com.sg.pnx.util.InitUtil$.init(InitUtil.scala:17)
at com.sg.pnx.Game$.delayedEndpoint$com$sg$pnx$Game$1(Game.scala:17)
at com.sg.pnx.Game$delayedInit$body.apply(Game.scala:13)
at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
# JS config for NVIDIA SHIELD
# Axes:
# -----
# 1 Left stick H
# 2 Left stick V
# 3 Left trigger
# 4 Right stick H
# 5 Right stick V
# 6 Right trigger
# 7 Pad H