using Distributions

# config 
Ks = [3, 10, 30, 100, 1000, 10000]
n = 10^5

function run_sample(sampler, n::Int)
	for i = 1:n
		rand(sampler)
	end
end


macro bench_sampler(construct_expr)
	quote
		s = $(esc(construct_expr)) # construct sampler
		tname = typeof(s)

		# warm up
		run_sample(s, 100)

		et = @elapsed run_sample(s, n)

		mps = n * 1.0e-6 / et
		@printf("  %-28s :  elapsed = %12.6f sec  |  %8.4f MPS\n", 
			tname, et, mps)
	end
end


for K in Ks
	println("K = $K")
	println("-----------------------")

	p = fill(1/K, K)
	pu = fill(uint64(1), K)

	@bench_sampler DiscreteUniform(1, K)   # samples generated by rand(1:K)
	@bench_sampler Categorical(p)
	# @bench_sampler Distributions.DiscreteDistributionTable(p) 
	# @bench_sampler Distributions.huffman(1:K, pu)
	@bench_sampler Distributions.AliasTable(p)

	println()
end


