Skip to content

Commit

Permalink
Added Dart Implementation (v2) (PlummersSoftwareLLC#180)
Browse files Browse the repository at this point in the history
Dart solution by eagerestwolf
  • Loading branch information
eagerestwolf authored May 16, 2021
1 parent 6d4a8cf commit f9c9792
Show file tree
Hide file tree
Showing 6 changed files with 468 additions and 0 deletions.
117 changes: 117 additions & 0 deletions PrimeDart/solution_1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# File created using '.gitignore Generator' for Visual Studio Code: https://bit.ly/vscode-gig

# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,macos,dart,linux,windows
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,macos,dart,linux,windows

### Dart ###
# See https://www.dartlang.org/guides/libraries/private-files

# Files and directories created by pub
.dart_tool/
.packages
build/
# If you're building an application, you may want to check-in your pubspec.lock
pubspec.lock

# Directory created by dartdoc
# If you don't generate documentation locally you can remove this line.
doc/api/

# Avoid committing generated Javascript files:
*.dart.js
*.info.json # Produced by the --dump-info flag.
*.js # When generated by dart2js. Don't specify *.js if your
# project includes source files written in JavaScript.
*.js_
*.js.deps
*.js.map

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

### VisualStudioCode Patch ###
# Ignore all local history of files
.history
.ionide

### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,macos,dart,linux,windows

# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)

*.exe
*.aot
12 changes: 12 additions & 0 deletions PrimeDart/solution_1/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM google/dart
WORKDIR /app
ADD pubspec.* /app/
RUN pub get
ADD . /app
RUN pub get --offline
RUN dart2native /app/bin/PrimeDart.dart -o /app/bin/PrimeDart


FROM subfuzion/dart-scratch
COPY --from=0 /app/bin/PrimeDart /app/bin/PrimeDart
ENTRYPOINT [ "/app/bin/PrimeDart" ]
89 changes: 89 additions & 0 deletions PrimeDart/solution_1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Dart solution by Eagerestwolf

![Category](https://img.shields.io/badge/Category-faithful-green)

This implementation of the Prime Sieve uses the Dart Programming Language,
created by Google. The source file `bin/PrimeDart.dart` contains a lot of
comments to allow someone not familiar with Dart to understand what the code is
doing and why some things look a bit different to many other object oriented
programming languages (i.e. Java, C#, C++, etc). The reason such thorough
documentation is included is simple, Dave himself uses this algorithm when
learning a new language, so I think this is a good opportunity to teach others
a bit about Dart. So feel free to open that source file and take a read for
yourself!

## Run instructions

**NOTE**: Owners of an Apple Silicon Mac *must* use the Dart SDK method. The
Docker method will not work because Google does not publish arm64 images for
Dart, and QEMU does not like running x64 images on arm64. Not an issue with my
code, it's a known issue with Docker/QEMU/Dart's Docker images.

To run this solution, you must either have [Docker](https://www.docker.com) or
the [Dart SDK](https://dart.dev) installed.

To run the solution using Docker, run the following command:

```
docker build -t primes-dart .
docker run --rm -it primes-dart
```

To run the solution using the DartSDK, run the following command:

```
dart run
```

### Building and running

Dart supports compiling a native binary for your operating system and
architecture. This is only supported using the Dart SDK, but can lead to
increased speed. To compile the binary, run the following command:

```
dart compile exe bin/PrimeDart.dart
```

Then run the binary with the following command:

```
bin/PrimeDart.exe
```

**NOTE**: The executable will always have a `.exe` extension, regardless of
platform, but Dart will generate a standard ELF binary on *nix systems.

## Output

### Machine Specifications

* **Model**: MSI GF63 Thin 10SCXR
* **CPU**: Intel Core i5-10300H
* **Memory**: 16GB DDR4
* **GPU**: Nvidia GeForce GTX 1650 with Max-Q Design
* **OS**: Windows 10 (Build 19042)

### Docker Results

```
Passes: 1051, Time: 5.00003, Avg: 0.004757402473834443, Limit: 1000000, Count1: 1, Count2: 78498, Valid: true
eagerestwolf;1051;5.00003;1
```

### Dart SDK

```
Passes: 817, Time: 5.014207, Avg: 0.0061373402692778455, Limit: 1000000, Count1: 1, Count2: 78498, Valid: true
eagerestwolf;817;5.014207;1
```

### Dart Compiled

```
Passes: 849, Time: 5.000307, Avg: 0.005889643109540636, Limit: 1000000, Count1: 1, Count2: 78498, Valid: true
eagerestwolf;849;5.000307;1
```
14 changes: 14 additions & 0 deletions PrimeDart/solution_1/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Defines a default set of lint rules enforced for
# projects at Google. For details and rationale,
# see https://github.com/dart-lang/pedantic#enabled-lints.
include: package:pedantic/analysis_options.yaml

# For lint rules and documentation, see http://dart-lang.github.io/linter/lints.
# Uncomment to specify additional rules.
# linter:
# rules:
# - camel_case_types

analyzer:
# exclude:
# - path/to/excluded/files/**
Loading

0 comments on commit f9c9792

Please sign in to comment.