Sha256: 0ef3bc139b14c6f2245117ec98925a7ed4af38dba61d3fc039132fd71473eb3b

Contents?: true

Size: 1.72 KB

Versions: 35

Compression:

Stored size: 1.72 KB

Contents

#!/usr/bin/env ruby
require 'benchmark'
require 'socket'

ITERATIONS = 100000
REQUEST = " " * 800
REQUEST_SIZE = REQUEST.size
RESPONSE = " " * 5 * 1024
RESPONSE_SIZE = RESPONSE.size
PASSWORD = "x" * 128
PASSWORD_SIZE = PASSWORD.size

def start
	benchmark_with_password_checking
	puts ""
	benchmark_without_password_checking
end

def benchmark_with_password_checking
	puts "Benchmarking with password checking..."
	parent, child = UNIXSocket.pair
	pid = fork do
		parent.close
		ITERATIONS.times do
			password = child.read(PASSWORD_SIZE)
			if password == PASSWORD
				child.read(REQUEST_SIZE)
				child.write(RESPONSE)
				# This flush here improves performance significantly!
				child.flush
			else
				child.close
				break
			end
		end
	end
	child.close
	
	result = Benchmark.measure do
		ITERATIONS.times do
			parent.write(PASSWORD)
			parent.write(REQUEST)
			parent.flush
			parent.read(RESPONSE_SIZE)
		end
	end
	parent.close
	Process.waitpid(pid)
	puts "User/system/real time: #{result}"
	printf "%.2f messages per second\n", ITERATIONS / result.real
end

def benchmark_without_password_checking
	puts "Benchmarking without password checking..."
	parent, child = UNIXSocket.pair
	pid = fork do
		parent.close
		ITERATIONS.times do
			child.read(REQUEST_SIZE)
			child.write(RESPONSE)
			# This flush here improves performance significantly!
			child.flush
		end
	end
	child.close
	
	result = Benchmark.measure do
		ITERATIONS.times do
			parent.write(REQUEST)
			# We do not call flush. For some reason it degrades performance.
			parent.read(RESPONSE_SIZE)
		end
	end
	parent.close
	Process.waitpid(pid)
	puts "Without password checking:"
	puts "User/system/real time: #{result}"
	printf "%.2f messages per second\n", ITERATIONS / result.real
end

start

Version data entries

35 entries across 35 versions & 5 rubygems

Version Path
rockdog-passenger-0.0.1 benchmark/overhead_of_password_checking.rb
vanity-1.7.1 vendor/ruby/1.9.1/gems/passenger-2.2.15/benchmark/overhead_of_password_checking.rb
passenger-2.2.15 benchmark/overhead_of_password_checking.rb
passenger-2.2.14 benchmark/overhead_of_password_checking.rb
passenger-2.2.13 benchmark/overhead_of_password_checking.rb
passenger-2.2.12 benchmark/overhead_of_password_checking.rb
colouringcode-passenger-0.2 benchmark/overhead_of_password_checking.rb
passenger-2.2.11 benchmark/overhead_of_password_checking.rb
passenger-jmazzi-2.2.10 benchmark/overhead_of_password_checking.rb
passenger-2.2.10 benchmark/overhead_of_password_checking.rb
passenger-jmazzi-2.2.9 benchmark/overhead_of_password_checking.rb
passenger-2.2.9 benchmark/overhead_of_password_checking.rb
passenger-2.2.8 benchmark/overhead_of_password_checking.rb
colouringcode-passenger-0.1 benchmark/overhead_of_password_checking.rb
passenger-2.2.7 benchmark/overhead_of_password_checking.rb
passenger-2.2.6 benchmark/overhead_of_password_checking.rb
passenger-2.2.5 benchmark/overhead_of_password_checking.rb
passenger-2.2.3 benchmark/overhead_of_password_checking.rb
passenger-2.2.4 benchmark/overhead_of_password_checking.rb
passenger-1.0.1 benchmark/overhead_of_password_checking.rb