a-conjecture-of-mine

An exercise on polyglossy: the same problem solved on multiple languages

commit e0933798b0fdbae94bf4fe49334e47920dbf74fd
parent 475301d7e02ab1acc3736b3095c40188e6dfa47c
Author: Pablo Emilio Escobar Gaviria <pablo-escobar@riseup.net>
Date:   Sun, 23 Aug 2020 16:59:05 -0300

Benchmarked the C++ implementation

Diffstat:
MMakefile | 4++++
Mc++/main.cpp | 6+++---
Mc/main.c | 14+++++---------
Mstats.csv | 9+++------
4 files changed, 15 insertions(+), 18 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,6 +1,9 @@
 c-bin:
 	gcc -O2 -pthread -o bin/c ./c/main.c
 
+cpp-bin:
+	g++ -O2 -o ./bin/cpp -std=c++11 -pthread ./c++/main.cpp
+
 elixir-bin:
 	elixirc -o bin/elixir ./elixir/main.ex
 
@@ -26,6 +29,7 @@ ocaml-bin:
 		ocamlopt                 \
 		-thread                  \
 		-package threads         \
+		-nodynlink               \
 		-o ./bin/ocaml           \
 		-linkpkg ./ocaml/main.ml \
 	  && rm ./ocaml/*.cmi ./ocaml/*.cmx ./ocaml/*.o
diff --git a/c++/main.cpp b/c++/main.cpp
@@ -1,10 +1,8 @@
-#include <chrono>
 #include <iostream>
 #include <string>
 #include <thread>
 #include <map>
 #include <vector>
-//#include <charconv>
 
 #define SUCCESS 0
 #define FAIL 1
@@ -24,7 +22,9 @@ inline unsigned int sum_digits(unsigned int n)
     return sum;
 }
 
-void get_counterexpl_thread(unsigned int start, unsigned int max, unsigned int interval)
+void get_counterexpl_thread(unsigned int start, 
+                            unsigned int max, 
+                            unsigned int interval)
 {
     for (auto a = start; a <= max; a += interval)
         for (auto b = a; b <= max; b++)
diff --git a/c/main.c b/c/main.c
@@ -64,17 +64,13 @@ int counterexempl(range *r)
 
 int main(int argc, char *argv[])
 {
-    if (argc > 1)
+    if (argc > 2)
     {
         unsigned int max = strtoul(argv[1], NULL, 10);
-	if (!max) return INVALID_INPUT;
+	      if (!max) return INVALID_INPUT;
 
-        unsigned int n_threads = 1;
-        if (argc > 2)
-        {
-            n_threads = strtoul(argv[2], NULL, 10);
-            if (!n_threads) return INVALID_INPUT;
-        }
+        unsigned int n_threads = strtoul(argv[2], NULL, 10);
+        if (!n_threads) return INVALID_INPUT;
 
         pthread_t thread_ids[n_threads];
         range thread_ranges[n_threads];
@@ -88,7 +84,7 @@ int main(int argc, char *argv[])
         // Divide the task into the specified number of threads 
         for (int i = 0; i < n_threads; i++)
         {
-	    thread_ranges[i] = (range){i, n_threads, max};
+	          thread_ranges[i] = (range){i, n_threads, max};
             err = pthread_create(
                 &thread_ids[i],
                 NULL, 
diff --git a/stats.csv b/stats.csv
@@ -1,6 +1,3 @@
-C,15.441,4
-Rust,42.508,4
-Kotlin,12480,1
-OCaml,30448,1
-Go,70459,4
-Haskell,121000,1
+Rust,1.7807,1
+C,3.9135,1
+C++,53.795,1