Skip to content

Commit

Permalink
Add benchmark (#3)
Browse files Browse the repository at this point in the history
* m should be added for linux

* update

* fix

* minor fixes
  • Loading branch information
egecetin authored Oct 16, 2022
1 parent 5b29234 commit 119a0e9
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 10 deletions.
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)

# Compile
add_library(kaleidoscope-static ${KaleidoscopeSources})
if(CMAKE_C_COMPILER_ID MATCHES "GNU"
OR CMAKE_CXX_COMPILER_ID MATCHES "GNU"
OR CMAKE_C_COMPILER_ID MATCHES "(Apple)?[Cc]lang"
OR CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?[Cc]lang")
target_link_libraries(kaleidoscope-static m)
endif()

add_executable(kaleidoscope-cmd ${CMAKE_CURRENT_SOURCE_DIR}/src/kaleidoscope-cmd.c)
target_link_libraries(kaleidoscope-cmd kaleidoscope-static turbojpeg-static)
if(CMAKE_C_COMPILER_ID MATCHES "GNU"
OR CMAKE_CXX_COMPILER_ID MATCHES "GNU"
OR CMAKE_C_COMPILER_ID MATCHES "(Apple)?[Cc]lang"
OR CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?[Cc]lang")
target_link_libraries(kaleidoscope-cmd m)
endif()
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Use the following commands,

```
mkdir build && cd build
cmake -DNDEBUG ..
cmake -DCMAKE_BUILD_TYPE=Release -DNDEBUG=1 ..
cmake --build .
```

Expand All @@ -33,7 +33,15 @@ Alternatively you can directly use the command line program to create kaleidosco
You can see an example below for ```N=8```

<div align="center">
<img src="data/ac-synin.jpg" width="425"/> <img src="data/ac-synin-out.jpg" width="425"/>
<br>
<small>Image source: AC Valhalla</small>
<img src="data/ac-synin.jpg" width="425"/> <img src="data/ac-synin-out.jpg" width="425"/>
<br>
<small>Image source: AC Valhalla</small>
</div>

## Benchmark

It is really fast! On a Intel i7-11800H CPU it achieves ~135 FPS for a Full HD (1920 x 1080) image

If you want to benchmark code on your system use this command,

```./kaleidoscope <Input Image Path> <Output Image Path> <N> <Number of loop>```
Binary file modified data/ac-synin-out.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/jpeg-utils/jpeg-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ int saveImage(const char *path, ImageData *img, enum TJPF pixelFormat, enum TJSA
int retval = EXIT_FAILURE;

FILE *fptr = NULL;
unsigned int outSize = 0;
long unsigned int outSize = 0;
unsigned char *compImg = NULL;
tjhandle jpegCompressor = NULL;

Expand Down
25 changes: 21 additions & 4 deletions src/kaleidoscope-cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(int argc, char *argv[])
{
char *path = NULL, *outPath = NULL;
int n = 6, retval = EXIT_FAILURE;
int n = 6, retval = EXIT_FAILURE, benchmark = 0;
double k = 0.30;
double scaleDown = 0.45;
unsigned long long ctr, maxCtr = 0;
double startTime, endTime;

KaleidoscopeHandle handler;
ImageData imgData, outData;
Expand All @@ -26,8 +29,12 @@ int main(int argc, char *argv[])
path = argv[1];
outPath = argv[2];
n = atoi(argv[3]);

if (argc > 4)
if (argc == 5)
{
benchmark = 1;
maxCtr = atoll(argv[4]);
}
if (argc == 6)
{
k = atof(argv[4]);
scaleDown = atof(argv[5]);
Expand All @@ -47,9 +54,19 @@ int main(int argc, char *argv[])
printf(" %d\n", !retval);

printf("Processing ...");
processKaleidoscope(&handler, k, &imgData, &outData);
startTime = (float)clock() / CLOCKS_PER_SEC;
for (ctr = 0; ctr < maxCtr; ++ctr)
{
processKaleidoscope(&handler, k, &imgData, &outData);
if (!benchmark)
break;
}
endTime = (float)clock() / CLOCKS_PER_SEC;
printf(" 1\n");

if (benchmark)
printf("FPS %5.3f\n", 1 / ((endTime - startTime) / maxCtr));

printf("Saving %s... ", outPath);
if ((retval = saveImage(outPath, &outData, TJPF_RGB, TJSAMP_444, 90)))
return retval;
Expand Down
2 changes: 1 addition & 1 deletion src/kaleidoscope.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ int initKaleidoscope(KaleidoscopeHandle *handler, int n, int width, int height,
// Parameters of triangle
const double topAngle = 360.0 / n;
const double tanVal = tan(topAngle / 2.0 * M_PI / 180.0); // tan(topAngle / 2) in radians
const int triangleHeight = min((int)round(width / (2.0 * tanVal)), height - 1);
const int triangleHeight = (int)fmin(round(width / (2.0 * tanVal)), height - 1);

// Offsets
const int heightStart = (height - triangleHeight) / 2;
Expand Down

0 comments on commit 119a0e9

Please sign in to comment.