Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisIsNoahEvans committed Nov 14, 2023
1 parent b74d6f8 commit f9f3622
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ go.work
.DS_Store

# binary
resizer
resizer

# test output
test_images/imagemagick-output
test_images/resizer-output
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ Resize images by specifying the file paths and desired sizes:
Supported formats: JPEG, PNG, GIF.

Output files are saved in the same directory as the source, appended with the specified size. For example, `./resizer /path/to/image.png 1024` creates `/path/to/image_1024x1024.png`.

## Speed
Using `test.sh`, a very quick test I wrote, Resizer is *221 seconds faster than ImageMagick**
```
Comparison:
Resizer: 23 seconds
ImageMagick: 44 seconds
```
47 changes: 47 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash
CURRENT_DIR=$(pwd)

# Directory containing PNG images
IMAGE_PATH="$CURRENT_DIR/test_images/image.png"

# Output directory for Resizer
RESIZER_OUTPUT_DIR="$CURRENT_DIR/test_images/resizer-output"

# Output directory for ImageMagick
IMAGEMAGICK_OUTPUT_DIR="$CURRENT_DIR/test_images/imagemagick-output"

# Ensure output directories exist
mkdir -p "$RESIZER_OUTPUT_DIR"
mkdir -p "$IMAGEMAGICK_OUTPUT_DIR"

# Path to the Resizer executable
RESIZER_PATH="./resizer"

# Number of iterations
ITERATIONS=100

# Start timing Resizer
START_TIME=$(date +%s)
for i in $(seq 1 $ITERATIONS); do
$RESIZER_PATH "$IMAGE_PATH" 1024x1024
done
END_TIME=$(date +%s)
RESIZER_DURATION=$((END_TIME - START_TIME))
echo "Resizer took $RESIZER_DURATION seconds."

# Move Resizer output to its directory
mv "${IMAGE_PATH%.*}"*_1024x1024.png "$RESIZER_OUTPUT_DIR"

# Start timing ImageMagick
START_TIME=$(date +%s)
for i in $(seq 1 $ITERATIONS); do
convert "$IMAGE_PATH" -resize 1024x1024 "$IMAGEMAGICK_OUTPUT_DIR/$(basename "${IMAGE_PATH%.*}")_$i.png"
done
END_TIME=$(date +%s)
IMAGEMAGICK_DURATION=$((END_TIME - START_TIME))
echo "ImageMagick took $IMAGEMAGICK_DURATION seconds."

# Compare times
echo "Comparison:"
echo "Resizer: $RESIZER_DURATION seconds"
echo "ImageMagick: $IMAGEMAGICK_DURATION seconds"
Binary file added test_images/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f9f3622

Please sign in to comment.