Skip to content

Commit

Permalink
Bf-tests improvements and maintanance update (#287)
Browse files Browse the repository at this point in the history
* Re-run bf mandel tests (addressing #258).

* Maintenance update (#261)

* Re-run bf mandel tests (addressing #258).
* Preparation for Perl 7.
* Lua module conflicts have been resolved.

* Update README.md

Fixed UPDATE date.

* Maintenance update (#265)

* Added workaround for Intel JCC bug (#263).

* Maintenance update.

* Added JCC bugfix flag to clang. (#266)

* Vala numbers have been updated. (#268)

* Update test_dawjsonlink.cpp (#271)

Updated code to reflect API changes in v2 of DAW JSON Link

* Maintenance update with the renamed tests (#269). (#270)

* Switch the simdjson code to On Demand (#272)

* Updating simdjson to 0.6 API (on demand).

* Making things safer by specifying the commit + removing unnecessary std:: qualifiers.

* Minor changes following review

* Maintenance update and simdjson test changes (#273)

* Maintenance update

* Maintenance update and simdjson test changes.

* The JSON key ordering tests have been added. (#275)

* Boost.JSON test has been added and the old test has been renamed. (#277)

* Updated to use better numbers for floating point ops, changed Boost.JSON test to use doubles. (#279)

* Improved precisions of the tests (#281)

* Median cals have been added.

* Try another formatting.

* Changed memory calculations.

* Printing has been moved out from JSON benchmarks.

* Up-to-dated results.

* TOC updated.

* Typo

* Added printer to Scheme langs.

* Racket code has been fixed to use idiomatic struct instead of macros.

* C++ and Kotlin tests have been updated.

* D tests have been fixed to use proper initializations.

* Go and Elixir tests have improved.

* Nim microoptimization have been removed.

* Julia test has been updated.

* All haskell tests have been updated.

* Lua tests have been improved.

* OCaml tests have been improved.

* SML tests have been improved.

* Fsharp test has been improved.

* Tcl tests have been improved.

* Perl tests have been updated to use v5.32.

* Other tests have been fixed.

* Haskell networking has been fixed.

* Fixed JS code.

Co-authored-by: Darrell Wright <beached@users.noreply.github.com>
Co-authored-by: Daniel Lemire <lemire@gmail.com>
  • Loading branch information
3 people committed Dec 3, 2020
1 parent 65ecba2 commit db679b0
Show file tree
Hide file tree
Showing 67 changed files with 2,533 additions and 1,210 deletions.
484 changes: 245 additions & 239 deletions README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions analyze.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

ATTEMPTS.times do |n|
puts "--- Iteration #{n + 1}"
ENV['QUIET'] = '1'
exit unless system(*ARGV)
end
end
Expand Down
8 changes: 4 additions & 4 deletions base64/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ artifacts := $(executables) \
target/Base64Java.class \
target/Test-kt.jar \
target/test.exe \
target/Release/netcoreapp3.1/base64.dll
target/Release/net5.0/base64.dll

all_runners := $(patsubst %,run[%], $(artifacts)) \
run[test.pl] \
Expand Down Expand Up @@ -104,8 +104,8 @@ base64.rs/target/release/base64: $(base64-rs-toml)
target/test.exe: test.cs | target
$(MCS_BUILD)

.PHONY: target/Release/netcoreapp3.1/base64.dll
target/Release/netcoreapp3.1/base64.dll: base64.csproj | target
.PHONY: target/Release/net5.0/base64.dll
target/Release/net5.0/base64.dll: base64.csproj | target
$(DOTNET_BUILD)

target/base64_v_gcc: test.v | $(v_fmt)
Expand Down Expand Up @@ -141,7 +141,7 @@ run[target/Test-kt.jar]:: run[%]: %
run[target/test.exe]:: run[%]: %
$(MONO_RUN)

run[target/Release/netcoreapp3.1/base64.dll]:: run[%]: %
run[target/Release/net5.0/base64.dll]:: run[%]: %
$(DOTNET_RUN)

.PHONY: base64_perl
Expand Down
2 changes: 1 addition & 1 deletion base64/base64.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
</Project>
8 changes: 3 additions & 5 deletions base64/base64.rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion base64/base64.rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.0.1"
edition = "2018"

[dependencies]
base64 = "0.12.3"
base64 = "0.13.0"

[profile.release]
lto = true
5 changes: 3 additions & 2 deletions base64/test-xs.pl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use v5.12;
use v5.32;
use warnings;
no feature qw(indirect);
use feature qw(signatures);
no warnings qw(experimental::signatures);
no warnings qw(experimental);

use MIME::Base64 qw(encode_base64 decode_base64);
use Time::HiRes 'time';
Expand Down
7 changes: 5 additions & 2 deletions base64/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
'use strict';

const assert = require("assert");
const net = require('net');
const util = require('util');

const STR_SIZE = 131072;
Expand All @@ -9,7 +12,7 @@ async function main() {
const str2 = b.toString('base64');
const str3 = Buffer.from(str2, 'base64');

await notify(`Node.js\t${require('process').pid}`);
await notify(`Node.js\t${process.pid}`);

var s_encoded = 0;
const start = new Date();
Expand Down Expand Up @@ -40,7 +43,7 @@ async function main() {

function notify(msg) {
return new Promise(resolve => {
const client = require('net').connect(9001, 'localhost', () => {
const client = net.connect(9001, 'localhost', () => {
client.end(msg, 'utf8', () => {
client.destroy();
resolve();
Expand Down
5 changes: 3 additions & 2 deletions base64/test.pl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use v5.12;
use v5.32;
use warnings;
no feature qw(indirect);
use feature qw(signatures);
no warnings qw(experimental::signatures);
no warnings qw(experimental);

use MIME::Base64::Perl qw(encode_base64 decode_base64);
use Time::HiRes 'time';
Expand Down
8 changes: 5 additions & 3 deletions base64/test.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import net
import time

fn notify(msg string) {
sock := net.dial('127.0.0.1', 9001) or {
sock := net.dial_tcp('127.0.0.1:9001') or {
return
}
sock.write(msg) or { }
sock.close() or { }
defer {
sock.close()
}
sock.write_str(msg) or { }
}

fn main() {
Expand Down
28 changes: 14 additions & 14 deletions brainfuck/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ executables := \
target/bin_c_clang

artifacts := $(executables) \
fsharp/target/Release/netcoreapp3.1/brainfuck.dll \
fsharp/target/Release/net5.0/brainfuck.dll \
target/bf_scala.jar \
target/bf2-kt.jar \
target/bf.exe \
target/Release/netcoreapp3.1/brainfuck.dll \
target/Release/net5.0/brainfuck.dll \
target/bf.class

fast_runners := $(patsubst %,run[%], $(artifacts)) \
Expand Down Expand Up @@ -74,12 +74,12 @@ target/bf_scala.jar: bf.scala | target
target/bf.exe: bf.cs | target
$(MCS_BUILD)

.PHONY: target/Release/netcoreapp3.1/brainfuck.dll
target/Release/netcoreapp3.1/brainfuck.dll: brainfuck.csproj | target
.PHONY: target/Release/net5.0/brainfuck.dll
target/Release/net5.0/brainfuck.dll: brainfuck.csproj | target
$(DOTNET_BUILD)

.PHONY: fsharp/target/Release/netcoreapp3.1/brainfuck.dll
fsharp/target/Release/netcoreapp3.1/brainfuck.dll: fsharp/brainfuck.fsproj | target
.PHONY: fsharp/target/Release/net5.0/brainfuck.dll
fsharp/target/Release/net5.0/brainfuck.dll: fsharp/brainfuck.fsproj | target
$(DOTNET_BUILD)

target/bf2-kt.jar: bf2.kt | target
Expand All @@ -106,10 +106,10 @@ target/bin_nim_clang: bf.nim | target
target/bin_nim_gcc: bf.nim | target
$(NIM_GCC_BUILD)

target/bin_hs: bf.hs | target
target/bin_hs: bf.hs | $(hlint)
$(GHC_BUILD)

target/bin_hs_marray: bf-marray.hs | target
target/bin_hs_marray: bf-marray.hs | $(hlint)
$(GHC_BUILD)

target/bin_ocaml: bf.ml | target
Expand Down Expand Up @@ -164,10 +164,10 @@ run[target/bf_scala.jar]:: run[%]: %
run[target/bf.exe]:: run[%]: %
$(MONO_RUN) $(BF_SRC)

run[target/Release/netcoreapp3.1/brainfuck.dll]:: run[%]: %
run[target/Release/net5.0/brainfuck.dll]:: run[%]: %
$(DOTNET_RUN) $(BF_SRC)

run[fsharp/target/Release/netcoreapp3.1/brainfuck.dll]:: run[%]: %
run[fsharp/target/Release/net5.0/brainfuck.dll]:: run[%]: %
$(DOTNET_RUN) $(BF_SRC)

run[target/bf2-kt.jar]:: run[%]: %
Expand Down Expand Up @@ -208,13 +208,13 @@ run[jruby][bf.rb]:: run[jruby][%]: % | $(rubocop)

.PHONY: lua-deps
lua-deps:
$(LUAROCKS_LUA) install luasocket
$(LUAROCKS_LUA) install luaposix
$(LUAROCKS_LUA) install luasocket > /dev/null
$(LUAROCKS_LUA) install luaposix > /dev/null

.PHONY: luajit-deps
luajit-deps:
$(LUAROCKS_LUAJIT) install luasocket
$(LUAROCKS_LUAJIT) install luaposix
$(LUAROCKS_LUAJIT) install luasocket > /dev/null
$(LUAROCKS_LUAJIT) install luaposix > /dev/null

run[bf.lua]:: run[%]: % | lua-deps
$(LUA_RUN) $(BF_SRC)
Expand Down
111 changes: 87 additions & 24 deletions brainfuck/bf-marray.hs
Original file line number Diff line number Diff line change
@@ -1,19 +1,50 @@
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE ScopedTypeVariables #-}

module Main where

import qualified Data.Array.Base as ArrayBase
import qualified Data.Array.IO as IOUArray
import qualified Data.Array.MArray as MArray
import qualified Data.ByteString.Char8 as C
import Network.Simple.TCP
import Data.Char (chr)
import System.Environment (getArgs)
import Control.Exception
import Control.Monad
import Data.Bits
import Data.Char
import Data.Maybe
import Network.Socket
import Network.Socket.ByteString
import System.Environment
import System.Exit
import System.IO (hFlush, stdout)
import System.Posix (getProcessID)
import Text.RawString.QQ

data Op = Inc !Int | Move !Int | Print | Loop ![Op] deriving Show
data Tape = Tape { tapeData :: IOUArray.IOUArray Int Int
, tapePos :: !Int
}
data Printer = Printer { sum1 :: Int
, sum2 :: Int
, quiet :: Bool
}

write :: Printer -> Int -> IO Printer
write p n = if quiet p
then do let s1 = mod (sum1 p + n) 255
let s2 = mod (s1 + sum2 p) 255
return Printer {
sum1=s1,
sum2=s2,
quiet=True
}
else do
putStr [chr n]
hFlush stdout
return p

getChecksum :: Printer -> Int
getChecksum p = (sum2 p `shiftL` 8) .|. sum1 p

current :: Tape -> IO Int
current tape = ArrayBase.unsafeRead (tapeData tape) (tapePos tape)
Expand All @@ -30,11 +61,12 @@ move m tape = do
then return curData
else do
el <- MArray.getElems curData
MArray.newListArray (0, newPos) (el ++ [0 | i <- [len..newPos]])
MArray.newListArray (0, newPos)
(el ++ replicate (newPos - len + 1) 0)
return $ Tape newData newPos
where
curData = tapeData tape
newPos = (tapePos tape) + m
newPos = tapePos tape + m

parse :: ([Char], [Op]) -> ([Char], [Op])
parse ([], acc) = ([], reverse acc)
Expand All @@ -50,41 +82,72 @@ parse (c:cs, acc) =
']' -> (cs, reverse acc)
_ -> parse (cs, acc)

run :: [Op] -> Tape -> IO Tape
run [] tape = return tape
run (op:ops) tape = do
run :: [Op] -> Tape -> Printer -> IO (Tape, Printer)
run [] tape p = return (tape, p)
run (op:ops) tape p = do
case op of
Inc d -> do
inc d tape
run ops tape
run ops tape p
Move m -> do
newTape <- move m tape
run ops newTape
run ops newTape p
Print -> do
x <- current tape
putStr $ [chr x]
hFlush stdout
run ops tape
newP <- write p x
run ops tape newP
Loop loop ->
let go tape = do
x <- current tape
if x == 0 then run ops tape
else run loop tape >>= go
in go tape
let go (newTape, newP) = do
x <- current newTape
if x == 0 then run ops newTape newP
else run loop newTape newP >>= go
in go (tape, p)

notify msg = do
connect "localhost" "9001" $ \(socket, _) -> do
send socket $ C.pack msg
notify :: String -> IO ()
notify msg = withSocketsDo $ do
addr <- resolve
catch (_notify addr) (\(_ :: IOException) -> return ())
where
writeMsg s = sendAll s $ C.pack msg
resolve = do
let hints = defaultHints { addrSocketType = Stream }
head <$> getAddrInfo (Just hints) (Just "localhost") (Just "9001")
_notify addr = bracket (openSocket addr) close $ \sock -> do
connect sock $ addrAddress addr
writeMsg sock

verify :: IO ()
verify = do
let source = [r|++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>\
---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.|]
let (_, ops) = parse (source, [])
empty <- MArray.newListArray (0, 0) [0]
(_, pLeft) <- run ops
(Tape empty 0)
Printer {sum1=0, sum2=0, quiet=True}
let left = getChecksum pLeft

pRight <- foldM (\p c -> write p $ ord c)
(Printer {sum1=0, sum2=0, quiet=True})
"Hello World!\n"
let right = getChecksum pRight
when (left /= right)
$ die $ show left ++ " != " ++ show right

main :: IO ()
main = do
verify
[filename] <- getArgs
source <- readFile filename
quiet_env <- lookupEnv "QUIET"
let p = Printer {sum1=0, sum2=0, quiet=isJust quiet_env}

pid <- getProcessID
notify $ "Haskell (MArray)\t" ++ show pid

let (_, ops) = parse (source, [])
empty <- MArray.newListArray (0, 0) [0]
run ops $ Tape empty 0

(_, newP) <- run ops (Tape empty 0) p
notify "stop"

when (quiet newP)
$ do putStrLn $ "Output checksum: " ++ show (getChecksum newP)

0 comments on commit db679b0

Please sign in to comment.