Last active
December 29, 2015 21:59
-
-
Save ymizushi/7733260 to your computer and use it in GitHub Desktop.
clojureのevalとmacroで実行時間を比較
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
for file in `seq 0 19` | |
do | |
clj eval_performance.clj >> bench.txt | |
done | |
python bench.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
eval_sum = 0.0 | |
macro_sum = 0.0 | |
fn_sum = 0.0 | |
dotimes_sum = 0.0 | |
line_num = 0 | |
for line in open('./bench.txt', 'r'): | |
if line.find("eval") != -1: | |
num = line.split(' ')[3] | |
eval_sum += float(num) | |
if line.find("macro") != -1: | |
num = line.split(' ')[3] | |
macro_sum += float(num) | |
if line.find("fn") != -1: | |
num = line.split(' ')[3] | |
fn_sum += float(num) | |
if line.find("dotimes") != -1: | |
num = line.split(' ')[3] | |
dotimes_sum += float(num) | |
line_num += 1 | |
divider = line_num/4 | |
print "eval:", eval_sum/divider | |
print "macro:", macro_sum/divider | |
print "fn:", fn_sum/divider | |
print "dotimes:", dotimes_sum/divider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use 'clojure.core) | |
(use 'clojure.test) | |
(defn eval-sample [] | |
(eval `(* 10 10))) | |
(defmacro macro-sample [] | |
`(* 10 10)) | |
(defn fn-sample [] | |
(* 10 10)) | |
(defn bench [] | |
(do | |
(print "eval: ") (time (dotimes [_ 10000] (eval-sample))) | |
(print "macro: ") (time (dotimes [_ 10000] (macro-sample))) | |
(print "fn: ") (time (dotimes [_ 10000] (fn-sample))) | |
(print "dotimes: ") (time (dotimes [_ 10000])))) | |
(bench) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment