Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge upstream V fixes #983

Merged
merged 3 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions BENCHMARK.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Some solutions are not included in the automated benchmark runs, either because
- [Running a benchmark of all solutions for a particular language](#running-a-benchmark-of-all-solutions-for-a-particular-language)
- [Running in unconfined mode](#running-in-unconfined-mode)
- [Output formats](#output-formats)
- [Setting the solution timeout](#setting-the-solution-timeout)

## What operating system to use?

Expand Down Expand Up @@ -375,3 +376,13 @@ The output format can be controlled via the `FORMATTER` variable like this:
make FORMATTER=json
make DIRECTORY=PrimeCrystal/solution_1 FORMATTER=csv
```

## Setting the solution timeout

The run of each solution is limited to a certain duration, which is 10 minutes by default.
You can change this setting through the `TIMEOUT` variable like this:

```shell
make TIMEOUT=15
make DIRECTORY=PrimeCPP/solution_2 TIMEOUT=15
```
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ SHELL := /bin/bash

DIRECTORY := $(shell pwd)
FORMATTER := "table"
TIMEOUT := "10"

.PHONY: all
all: benchmark
Expand All @@ -14,6 +15,7 @@ benchmark: check-env
ARGS=("-d $${REALPATH}" "-f $(FORMATTER)"); \
[ ! -z $${OUTPUT_FILE} ] && ARGS+=( "-o $${OUTPUT_FILE}" ); \
[ ! -z $${UNCONFINED} ] && ARGS+=( "--unconfined" ); \
[ ! -z $${TIMEOUT} ] && ARGS+=( "-t $${TIMEOUT}" ); \
cd ./tools; npm ci --silent && npm start --silent -- benchmark $${ARGS[@]}

.PHONY: check-env
Expand Down
2 changes: 1 addition & 1 deletion PrimeJulia/solution_1/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM julia:1.6-alpine3.13
FROM julia:1-alpine

WORKDIR /opt/app

Expand Down
2 changes: 1 addition & 1 deletion PrimeJulia/solution_2/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM julia:1.6.1-alpine3.13
FROM julia:1-alpine

WORKDIR /opt/app

Expand Down
2 changes: 1 addition & 1 deletion PrimeJulia/solution_3/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM julia:1.6-buster
FROM julia:1

WORKDIR /opt/app

Expand Down
4 changes: 2 additions & 2 deletions PrimeJulia/solution_3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ optimizations. This is a sort-of "low-level" style implementation in
Julia to get as much as speed as possible out of the language. It is
*not* designed to be idiomatic Julia code.

This solution requires at least **Julia 1.5** to run. Julia 1.6 is
This solution requires at least **Julia 1.5** to run. the latest stable 1.X Julia version is
recommended and is used in the Docker image.

## Description
Expand Down Expand Up @@ -40,7 +40,7 @@ and bits are unset when the number is *prime*. This simplifies the
set_bit operation slightly (`arr[i] |= mask vs. arr[i] &= ~mask`).

If you see any room for improvement in the code or have any
suggestions, don't hesitate to open an issue, pull request (PR),
suggestions, don't hesitate to open an issue, pull request (PR),
Discussion, or the like. Don't forget to tag me at `@louie-github` so I
can be notified if my personal input is either wanted or needed.
I'm open to fixing stylistic issues or discussing cosmetic changes to
Expand Down
2 changes: 1 addition & 1 deletion PrimeJulia/solution_4/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM julia:1.6-buster
FROM julia:1

WORKDIR /opt/app

Expand Down
42 changes: 20 additions & 22 deletions PrimeV/solution_1/primes.v
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
import time
import math

const (
sieve_size = 1_000_000
q = math.sqrt(sieve_size)
all_bits_true_array = []bool{len: sieve_size, init: true}
dictionary = {
'10': 4
'100': 25
'1000': 168
'10000': 1229
'100000': 9592
'1000000': 78498
'10000000': 664579
'100000000': 5761455
'1000000000': 50847534
'10000000000': 455052511
}
)
const sieve_size = 1_000_000
const q = math.sqrt(sieve_size)
const all_bits_true_array = []bool{len: sieve_size, init: true}
const dictionary = {
'10': 4
'100': 25
'1000': 168
'10000': 1229
'100000': 9592
'1000000': 78498
'10000000': 664579
'100000000': 5761455
'1000000000': 50847534
'10000000000': 455052511
}

struct Sieve {
sieve_size u64
mut:
bits []bool
}

[direct_array_access]
@[direct_array_access]
fn (mut sieve Sieve) run_sieve() {
mut factor := u64(3)

Expand Down Expand Up @@ -54,7 +52,7 @@ fn (sieve Sieve) print_results(show_results bool, duration time.Duration, passes
for num := u64(3); num <= sieve.sieve_size; num += u64(2) {
if sieve.bits[num] {
if show_results {
print('$num, ')
print('${num}, ')
}

count++
Expand All @@ -68,9 +66,9 @@ fn (sieve Sieve) print_results(show_results bool, duration time.Duration, passes
avg := f64(duration / passes)
count_primes := sieve.count_primes()
valid := (count_primes == u64(dictionary[sieve.sieve_size.str()]))
eprintln('Passes: $passes, Time: $duration, Avg: $avg, Limit: $sieve.sieve_size, Count1: $count, Count2: $count_primes, Valid: $valid')
eprintln('Passes: ${passes}, Time: ${duration}, Avg: ${avg}, Limit: ${sieve.sieve_size}, Count1: ${count}, Count2: ${count_primes}, Valid: ${valid}')

println('marghidanu;$passes;$duration;1;algorithm=base,faithful=yes')
println('marghidanu;${passes};${duration};1;algorithm=base,faithful=yes')
}

fn (sieve Sieve) count_primes() u64 {
Expand All @@ -92,7 +90,7 @@ fn main() {
for {
mut sieve := Sieve{
sieve_size: 1_000_000
bits: all_bits_true_array
bits: all_bits_true_array
}
sieve.run_sieve()

Expand Down
Loading