def encrypt_password
# This is just a place holder implementation for now
require 'digest'
self.password = Digest::SHA512.hexdigest(password)
end
# # A magic function that generates file tasks that copy all headers from # directory ind # to directory outd. Any missing directories are created as # needed. # # The return value is a list suitable for the right hand side of a task, e.g. # # task :headers => header_magic(src, dest) # def header_magic(ind, outd) dirs = [] hdrs = [] find_files(ind, /.*\.h[hxp]*$/) do |p| outdir = File.dirname p.sub(ind, outd) outfile = File.join(outd, File.basename(p)) directory outdir file outfile => p do cp_r p, outdir end dirs.push outdir hdrs.push outfile CLEAN.include outfile, outdir end dirs+hdrs end
method C RB C(-O3) Java Python Total iteration 2 1 3 2 2 10 recursion 3 2 2 1 1 9 original 1 3 1 3 3 11
#include <stdio.h>
#define A 1071
#define B 1029
int
mygcd( int a, int b ) {
int t = 0;
while ( b != 0 ) {
t = b;
b = a % b;
a = t;
}
return a;
}
int
main(void) {
mygcd(A, B);
return 0;
}
#include <stdio.h>
#define A 1071
#define B 1029
int
mygcd( int a, int b ) {
if ( b == 0 ) {
return a;
} else {
return mygcd( b, a%b );
}
}
int
main(void) {
mygcd(A, B);
return 0;
}
#include <stdio.h>
#define A 1071
#define B 1029
int
mygcd( int a, int b ) {
while ( b != 0 ) {
if ( a > b ) {
a = a-b;
} else {
b = b-a;
}
}
return a;
}
int
main(void) {
mygcd(A, B);
return 0;
}
#!/usr/local/bin/ruby -w
def gcd(a, b)
while b != 0
t = b
b = a % b
a = t
end
return a
gcd( 1071, 1029 )
#!/usr/local/bin/ruby -w
def gcd(a,b)
if b == 0
return a
else
return gcd(b, a % b )
end
end
gcd( 1071, 1029 )
#!/usr/local/bin/ruby -w
def gcd( a, b )
while b != 0
if a > b
a = a - b
else
b = b - a
end
end
return a
end
gcd( 1071, 1029 )
class EuclideanIteration {
static final int A = 1071;
static final int B = 1029;
public static int
mygcd( int a, int b ) {
int t = 0;
while ( b != 0 ) {
t = b;
b = a % b;
a = t;
}
return a;
}
public static void
main( String[] args ) {
mygcd(A, B);
}
}
class EuclideanRecursion {
static final int A = 1071;
static final int B = 1029;
public static int
mygcd( int a, int b ) {
if ( b == 0 ) {
return a;
} else {
return mygcd( b, a%b );
}
}
public static void
main( String[] args ) {
mygcd(A, B);
}
}
class EuclideanOriginal {
static final int A = 1071;
static final int B = 1029;
public static int
mygcd( int a, int b ) {
while ( b != 0 ) {
if ( a > b ) {
a = a-b;
} else {
b = b-a;
}
}
return a;
}
public static void
main( String[] args ) {
mygcd(A, B);
}
}
#!/usr/local/bin/python
def mygcd(a, b):
while b != 0:
t = b
b = a % b
a = t
return a
mygcd( 1071, 1029 )
#!/usr/local/bin/python
def mygcd( a, b ):
if b == 0:
return a
else:
return mygcd( b, a %b )
mygcd( 1071, 1029 )
#!/usr/local/bin/python
def mygcd( a, b ):
while b != 0:
if a > b:
a = a-b
else:
b = b-a
return a
mygcd( 1071, 1029 )
#!/usr/local/bin/ruby -w
# usage: make [opt] project [dir]
# TODO:
# rdoc...
# handle header files and linking properly in C
# support more then C
# implement a way to set lang opts/debug/profiler stuff correctly
# reduce usage of $globals
# clean up code... looks like sludge
require 'getoptlong'
require 'rdoc/usage'
$lang=nil
$project=''
$startdir=Dir.pwd
$debug=false
$profiler=false
$verbose=false
def main()
opts = GetoptLong.new(
[ '--help', '-h', GetoptLong::NO_ARGUMENT ],
[ '--lang', '-l', GetoptLong::REQUIRED_ARGUMENT ],
[ '--lang-opts', '-o', GetoptLong::REQUIRED_ARGUMENT ],
[ '--debug', '-d', GetoptLong::OPTIONAL_ARGUMENT ],
[ '--prof', '-p', GetoptLong::OPTIONAL_ARGUMENT ],
[ '--clean', '-c', GetoptLong::NO_ARGUMENT ],
[ '--verbose', '-v', GetoptLong::NO_ARGUMENT ]
)
begin
opts.each do |opt, arg|
case opt
when '--help'
RDoc::usage()
when '--lang'
proc_lang( arg )
when '--lang-opts'
puts "#{arg} -> --lang-opts not implemented!"
when '--debug'
$debug = true
when '--prof'
$profiler = arg
when '--verbose'
$verbose=true
end
end
if ARGV[0]
$project = ARGV[0]
end
if ARGV[1]
$startdir = ARGV[1]
end
puts ARGV #debug
puts "\n\n"
n=LangC.new()
n.make()
unless $lang
$stderr.puts( 'WARNING: --lang not set!, defaulting to ISO C99' )
end
# call usage() on *any* error and print the problem
rescue StandardError
puts( $! )
RDoc::usage()
end
end
def proc_lang( str )
case str
when 'c','C'
# set up for C
$lang=str
when 'c++','cpp','C++','C++','cc','CC','cxx','CXX'
# set up for C++
when 'java','Java'
# set up for Java
when 'Perl','pl', 'plx'
# Setup for Perl
when 'Python','py'
# Setup for Python
when 'Ruby','rb'
# set up for Ruby ;-)
end
end
class Lang
def make()
end
def each( startdir, &block )
dp = Dir.open(startdir) do |dir|
dir.each do |node|
if node == '.' or node == '..'
next
end
p = File.expand_path( node, startdir )
yield( p )
if File.directory?( p )
self.each( p, &block )
end
end
end
end
end # !class Lang
class LangC < Lang
@@compiler = 'gcc'
@@cflags = "-Wall -Wpointer-arith -Wcast-qual -Wcast-align " +
"-Wconversion -Waggregate-return -Wstrict-prototypes " +
"-Wmissing-prototypes -Wmissing-declarations " +
"-Wredundant-decls -Winline -Wnested-externs " +
"-std=c99 -march=i686 -pipe "
@@ldfags = nil
@@debug = '-g'
@@prof = nil
@filelist = Array.new()
# The very bloody boring constructor which serves only to override the
# defaults for our static class variables.
#
def initialize( compiler=false, cflags=false, ldflags=false,
debug=false, prof=false )
if compiler then @@compiler = compiler end
if cflags then @@cflags = cflags end
if ldflags then @@ldfags = ldflags end
if debug then @@debug = debug end
if prof then @@prof = prof end
@@ldflags=nil;@@prof=nil#debug
end
# Assemble project
def make()
@filelist = Array.new()
self.compile()
self.link()
end
# Walk the directory tree and compile all .c files into .o
#
def compile()
$stdout.puts '------- COMPILING -------' if $verbose
self.each( $startdir ) do |file|
if file =~ /.*\.c$/
p = file.to_s.gsub( File.extname(file),".o" )
@filelist.push( p )
# Don't compile unless the source is newer then the object files
if File.exists?( p )
next unless timecheck(file,p)
end
system( "#{@@compiler} #{@@cflags} #{@@debug} #{@@prof} " +
"#{file} -c -o #{p}" )
end
end
end
# Walk the directory tree and link all object files
def link()
$stdout.puts '------- LINKING -------' if $verbose
@filelist.each do |obj|
system( "#{@@compiler} #{@@cflags} #{@@ldflags} #{@@debug} " +
"#{@@prof} #{obj} -o #{$startdir}/#{$project}" )
end
end
# Return true if first filename has a newer time stamp then the second
#
def timecheck( f1, f2 )
File.mtime( f1 ) > File.mtime( f2 ) ? true : false
end
end
if __FILE__ == $0
main()
end