Skip to content

Commit e04a329

Browse files
committed
add rust fib and update versions
1 parent 2055e84 commit e04a329

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+185
-95
lines changed

README.md

Lines changed: 10 additions & 1 deletion

benchmark_type.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
OUTFILE=${BENCHMARK}_`date +%Y%m%d%H%M%S`.json
1+
NOW=`date +%Y%m%d%H%M%S`
2+
3+
OUTFILE=${BENCHMARK}_${NOW}_out.txt
24
./$BENCHMARK $ARGS > $OUTFILE
35

46
aws s3 cp $OUTFILE s3://$BUCKET/$TYPE/
5-
aws s3 cp /var/log/cloud-init-output.log s3://$BUCKET/$TYPE/
7+
aws s3 cp /var/log/cloud-init-output.log s3://$BUCKET/$TYPE/${BENCHMARK}_${NOW}_init.log
68

79
# https://stackoverflow.com/questions/10541363/self-terminating-aws-ec2-instance
810
# https://askubuntu.com/questions/578144/why-doesnt-running-sudo-shutdown-now-shut-down/578155

clean.sh

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@ do
1616

1717
for file in "${files[@]}"
1818
do
19-
if [[ $file =~ .*_.*\.json ]]; then
20-
aws s3 cp --profile $PROFILE s3://$BUCKET/$TYPE/$file ./${TYPE}_${file}
21-
aws s3 rm --profile $PROFILE s3://$BUCKET/$TYPE/$file
22-
elif [[ $file = cloud-init-output.log ]]; then
23-
aws s3 cp --profile $PROFILE s3://$BUCKET/$TYPE/$file ./${TYPE}-$file
24-
aws s3 rm --profile $PROFILE s3://$BUCKET/$TYPE/$file
25-
fi
19+
aws s3 cp --profile $PROFILE s3://$BUCKET/$TYPE/$file ./${TYPE}_${file}
20+
aws s3 rm --profile $PROFILE s3://$BUCKET/$TYPE/$file
2621
done
2722
done

clone_repo.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ export HOME=/root
55

66
apt-get update
77
apt-get install -yq git awscli
8+
apt-get autoremove -y
89

910
git clone https://github.com/rogusdev/countbits.git

countbits/c/build.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# https://github.com/json-c/json-c
22
# https://linuxprograms.wordpress.com/2010/05/20/json-c-libjson-tutorial/
33
git clone https://github.com/json-c/json-c.git
4-
cd json-c && sh autogen.sh && ./configure && make && make install && cd ..
5-
4+
mkdir json-c-build && cd json-c-build && cmake ../json-c
5+
make && make test && make USE_VALGRIND=0 test && make install
6+
cd ..
67

78
# https://gist.github.com/alan-mushi/19546a0e2c6bd4e059fd
8-
gcc -Wall -g -I/usr/local/include/json-c/ countbits.c -o countbits -ljson-c
9+
gcc -Wall -g -I/usr/local/include/json-c-build/ countbits.c -o countbits -ljson-c
910
# https://stackoverflow.com/questions/480764/linux-error-while-loading-shared-libraries-cannot-open-shared-object-file-no-s
1011
export LD_LIBRARY_PATH=/usr/local/lib

countbits/csharp/CountBits.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
4-
<TargetFramework>netcoreapp2.0</TargetFramework>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
55
</PropertyGroup>
66
<ItemGroup>
77
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />

countbits/csharp/build.sh

Whitespace-only changes.

countbits/elixir/build.sh

Whitespace-only changes.

countbits/go/run.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.

countbits/javascript_1/build.sh

Whitespace-only changes.

countbits/javascript_2/build.sh

Whitespace-only changes.

countbits/jruby/build.sh

Whitespace-only changes.

countbits/php/build.sh

Whitespace-only changes.

countbits/python3/build.sh

Whitespace-only changes.

countbits/ruby/build.sh

Whitespace-only changes.

fibonacci/c/build.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
gcc -Wall -g fibonacci.c -o fibonacci
1+
# https://www.oreilly.com/library/view/c-cookbook/0596007612/ch01s23.html
2+
gcc -Wall -O3 -finline-functions -g fibonacci.c -o fibonacci

fibonacci/csharp/Fibonacci.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp2.0</TargetFramework>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
66
</PropertyGroup>
77

88
</Project>

fibonacci/csharp/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
dotnet build
1+
dotnet build --configuration Release

fibonacci/csharp/fibonacci

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
dotnet bin/Debug/netcoreapp2.0/Fibonacci.dll $1
1+
dotnet bin/Release/netcoreapp3.1/Fibonacci.dll $1

fibonacci/elixir/build.sh

Whitespace-only changes.

fibonacci/java/Fibonacci.class

697 Bytes
Binary file not shown.

fibonacci/javascript/build.sh

Whitespace-only changes.

fibonacci/jruby/build.sh

Whitespace-only changes.

fibonacci/jruby/fibonacci

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
jruby ../ruby/fibonacci.rb $@

fibonacci/php/build.sh

Whitespace-only changes.

fibonacci/python3/build.sh

Whitespace-only changes.

fibonacci/ruby/build.sh

Whitespace-only changes.

fibonacci/ruby/fibonacci

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1 @@
1-
#!/usr/bin/env ruby
2-
3-
def recursive_fibonacci(n)
4-
if n < 1
5-
0
6-
elsif n == 1
7-
1
8-
else
9-
recursive_fibonacci(n - 1) + recursive_fibonacci(n - 2)
10-
end
11-
end
12-
13-
n = ARGV[0].to_i
14-
puts n
15-
16-
start = Time.now.to_f
17-
puts recursive_fibonacci(n)
18-
puts ((Time.now.to_f - start) * 1000).to_i
1+
ruby fibonacci.rb $@

fibonacci/ruby/fibonacci.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env ruby
2+
3+
def recursive_fibonacci(n)
4+
if n < 1
5+
0
6+
elsif n == 1
7+
1
8+
else
9+
recursive_fibonacci(n - 1) + recursive_fibonacci(n - 2)
10+
end
11+
end
12+
13+
n = ARGV[0].to_i
14+
puts n
15+
16+
start = Time.now.to_f
17+
puts recursive_fibonacci(n)
18+
puts ((Time.now.to_f - start) * 1000).to_i

fibonacci/rust/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
rustc fibonacci.rs
1+
rustc -C debuginfo=0 -C opt-level=3 fibonacci.rs

fibonacci/rust/fibonacci.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,31 @@
1-
// https://doc.rust-lang.org/book/second-edition/ch01-02-hello-world.html
2-
fn main() {
3-
println!("Hello, world!");
1+
use std::env;
2+
use std::time::{SystemTime};
3+
4+
fn recursive_fibonacci (n: i32) -> i32 {
5+
if n < 1 {
6+
0
7+
} else if n == 1 {
8+
1
9+
} else {
10+
recursive_fibonacci(n - 1) + recursive_fibonacci(n - 2)
11+
}
12+
}
13+
14+
fn main () {
15+
// https://doc.rust-lang.org/book/ch12-01-accepting-command-line-arguments.html
16+
let args: Vec<String> = env::args().collect();
17+
// https://doc.rust-lang.org/std/primitive.str.html#method.parse
18+
let n = args[1].parse::<i32>().unwrap();
19+
println!("{}", n);
20+
21+
// https://doc.rust-lang.org/std/time/struct.SystemTime.html
22+
let start = SystemTime::now();
23+
24+
println!("{}", recursive_fibonacci(n));
25+
26+
let dur = SystemTime::now()
27+
.duration_since(start)
28+
.expect("Time went backwards");
29+
30+
println!("{}", (dur.as_secs() * 1_000) + dur.subsec_millis() as u64)
431
}

run.sh

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ export BUCKET=...
44
REGION=us-east-1
55
KEYPAIR=ec2-keypair
66

7-
# https://cloud-images.ubuntu.com/locator/ec2/ # 64 us-east-1 ebs hvm
8-
IMAGEID=ami-6dfe5010
7+
# https://cloud-images.ubuntu.com/locator/ec2/ # amd64 us-east-1 ebs-ssd hvm
8+
IMAGEID=ami-013da1cc4ae87618c
99

1010

11-
export BENCHMARK=$1
11+
export BENCHMARK="$1"
1212

1313
# https://stackoverflow.com/questions/2427995/bash-no-arguments-warning-and-case-decisions
14-
if [[ $# -eq 0 ]]; then BENCHMARK='countbits'; fi
14+
if [[ $# -eq 0 ]]; then BENCHMARK="countbits"; fi
1515

16-
case "$1" in
16+
case "$BENCHMARK" in
1717
# https://unix.stackexchange.com/questions/62333/setting-a-shell-variable-in-a-null-coalescing-fashion
18-
fibonacci) export ARGS=${2:-42} ;;
18+
fibonacci) export ARGS="${2:-42}" ;;
1919
*) ;;
2020
esac
2121

@@ -29,6 +29,7 @@ echo $SGID
2929

3030
echo $PROFILE $REGION $BUCKET $TYPE $KEYPAIR $IMAGEID $SGID
3131

32+
NOW=`date +%Y%m%d%H%M%S`
3233

3334
# https://www.cyberciti.biz/faq/bash-for-loop-array/
3435
types=( c csharp elixir go java java_1 java_2 jruby javascript javascript_1 javascript_2 php python3 ruby rust )
@@ -44,18 +45,22 @@ do
4445
continue
4546
fi
4647

48+
echo ""
49+
4750
echo "aws s3 ls --profile $PROFILE $BUCKET/$TYPE/"
4851
aws s3 ls --profile $PROFILE $BUCKET/$TYPE/
4952

5053
# https://superuser.com/questions/133780/in-bash-how-do-i-escape-an-exclamation-mark
5154
# https://stackoverflow.com/questions/10683349/forcing-bash-to-expand-variables-in-a-string-loaded-from-a-file
5255
USERDATA=$(
53-
echo -e "#"'!'"/bin/bash\n\n# ----- CLONE -----\n"
56+
echo -e "#"'!'"/bin/bash\n"
57+
echo -e "\n# ----- CLONE -----\n"
5458
cat clone_repo.sh
5559
echo -e "\n# ----- SETUP -----\n"
5660
cat setup/$LANG/setup.sh
5761
echo -e "\n# ----- BUILD -----\n"
58-
echo -e "cd countbits/$BENCHMARK/$TYPE && . ./build.sh\n\n# ----- RUN AND COPY -----\n"
62+
echo -e "cd countbits/$BENCHMARK/$TYPE && . ./build.sh\n"
63+
echo -e "\n# ----- RUN AND COPY -----\n"
5964
envsubst \$BUCKET,\$BENCHMARK,\$TYPE,\$ARGS < benchmark_type.sh
6065
)
6166

@@ -79,7 +84,7 @@ do
7984
--profile $PROFILE \
8085
--region $REGION \
8186
--resources $INSTANCEID \
82-
--tags Key=Name,Value="$BENCHMARK $TYPE"
87+
--tags Key=Name,Value="$BENCHMARK $TYPE $NOW"
8388

8489
DOMAIN=$(aws ec2 describe-instances \
8590
--profile $PROFILE \
@@ -93,6 +98,7 @@ done
9398

9499
unset ARGS # in case it was set for fibonacci
95100

101+
echo ""
96102
echo "aws ec2 describe-instances --profile $PROFILE --region $REGION --query 'Reservations[*].Instances[*].[LaunchTime, InstanceId, State.Name, Tags[0].Value]' --output text"
97103

98104
aws ec2 describe-instances \

setup/c/setup.sh

100644100755
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
sudo apt-get install -yq build-essential gcc autoconf automake libtool
1+
sudo apt-get install -yq build-essential gcc autoconf automake libtool cmake
2+
3+
gcc --version

setup/csharp/setup.sh

100644100755
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/microsoft.gpg
2-
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial main" > /etc/apt/sources.list.d/dotnetdev.list'
1+
# https://docs.microsoft.com/en-us/dotnet/core/install/linux-ubuntu
2+
wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
3+
sudo dpkg -i packages-microsoft-prod.deb
34

4-
sudo apt-get update
5-
sudo apt-get install -yq dotnet-sdk-2.1.4
5+
sudo apt-get update; \
6+
sudo apt-get install -y apt-transport-https && \
7+
sudo apt-get update && \
8+
sudo apt-get install -y dotnet-sdk-3.1
69

710
# https://www.michaelcrump.net/part12-aspnetcore/
8-
export DOTNET_CLI_TELEMETRY_OPTOUT=1
11+
export DOTNET_CLI_TELEMETRY_OPTOUT=true
912

10-
# https://github.com/dotnet/cli/issues/6815
11-
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true
13+
# https://github.com/dotnet/sdk/issues/3828
14+
# export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true
15+
export DOTNET_NOLOGO=true
16+
# https://docs.microsoft.com/en-us/nuget/reference/cli-reference/cli-ref-environment-variables
17+
export NUGET_XMLDOC_MODE=skip
18+
19+
echo dotnet $(dotnet --version)

setup/elixir/setup.sh

100644100755
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# http://elixir-lang.github.io/install.html#unix-and-unix-like
2-
wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb
3-
sudo dpkg -i erlang-solutions_1.0_all.deb
2+
wget https://packages.erlang-solutions.com/erlang-solutions_2.0_all.deb
3+
sudo dpkg -i erlang-solutions_2.0_all.deb
44
sudo apt-get update
5-
sudo apt-get install -yq esl-erlang elixir
6-
rm erlang-solutions_1.0_all.deb
5+
sudo apt-get install -y esl-erlang elixir
6+
rm erlang-solutions_2.0_all.deb
77

88
# https://github.com/voxpupuli/puppet-rabbitmq/issues/671
9+
# https://github.com/elixir-lang/elixir/issues/3548
910
export LANG="en_US.UTF-8"
1011
export LC_ALL="en_US.UTF-8"
12+
13+
erl -version

setup/go/setup.sh

100644100755
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
# https://golang.org/doc/install && https://golang.org/dl/
1+
# https://golang.org/doc/install#download
22
sudo rm -rf /usr/local/go
3-
wget -L https://dl.google.com/go/go1.10.1.linux-amd64.tar.gz \
3+
wget -L https://golang.org/dl/go1.15.2.linux-amd64.tar.gz \
44
&& sudo tar -C /usr/local -xzf go*.tar.gz
55

6-
echo 'export PATH="/usr/local/go/bin:$PATH"' >> $HOME/.profile
7-
export PATH="/usr/local/go/bin:$PATH"
6+
echo 'export PATH=$PATH:/usr/local/go/bin' >> $HOME/.profile
7+
export PATH=$PATH:/usr/local/go/bin
8+
9+
go version

setup/java/setup.sh

100644100755
Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
# oracle java, probably best via some user PPA:
2-
# http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html
3-
# https://askubuntu.com/questions/190582/installing-java-automatically-with-silent-option/637514#637514
4-
# must switch to java 11 soon! http://www.oracle.com/technetwork/java/eol-135779.html
5-
sudo add-apt-repository -y ppa:webupd8team/java
6-
echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections
1+
. countbits/setup/setup_asdf.sh
72

8-
sudo apt-get update
9-
sudo apt-get install -yq oracle-java8-installer
3+
asdf plugin-add java https://github.com/halcyon/asdf-java.git
4+
asdf install java $VERSION_JAVA
5+
asdf global java $VERSION_JAVA
106

11-
export JAVA_HOME=/usr/lib/jvm/java-8-oracle
7+
java -version

setup/javascript/setup.sh

100644100755
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
1+
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
22

33
sudo apt-get update
44
sudo apt-get install -yq git nodejs
5+
6+
echo node $(node --version)

setup/jruby/setup.sh

100644100755
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
. countbits/setup/java/setup.sh
22

3-
curl https://repo1.maven.org/maven2/org/jruby/jruby-dist/9.1.16.0/jruby-dist-9.1.16.0-bin.tar.gz | tar xvz
3+
curl https://repo1.maven.org/maven2/org/jruby/jruby-dist/9.2.13.0/jruby-dist-9.2.13.0-bin.tar.gz | tar xvz
44
ln -s jruby-* jruby
55

66
export PATH=$(pwd)/jruby/bin:$PATH
7+
8+
jruby --version

setup/php/setup.sh

100644100755
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
sudo apt-get install -yq php7.0-cli
1+
sudo apt-get install -yq php-cli
2+
3+
php --version

setup/python3/setup.sh

100644100755
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
sudo apt-get install -yq python3
2+
3+
echo python3 $(python3 --version)

setup/ruby/setup.sh

100644100755
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
sudo apt-get install -yq build-essential gcc
1+
./countbits/setup/setup_asdf.sh # for dependencies like openssl
22

33
# https://github.com/rbenv/ruby-build/issues/156
4-
curl https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.1.tar.gz \
4+
curl https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.1.tar.gz \
55
| tar xvz && cd ruby-* && ./configure --disable-install-doc \
66
&& make && sudo make install && cd .. && rm -rf ruby-*
7+
8+
ruby --version

setup/rust/setup.sh

100644100755
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ curl https://sh.rustup.rs -sSf | sh -s -- -y
66

77
echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> $HOME/.profile
88
PATH="$HOME/.cargo/bin:$PATH"
9+
10+
rustc --version

0 commit comments

Comments
 (0)