commit fe2f8eb01d69608e1d5123a00e541180505d19f3
parent 0720a53642433e2da606d9528f485eeef44d811a
Author: Andrew Laack <andrew@laack.co>
Date: Sun, 18 Oct 2026 12:31:58 -0500
Improved UX
Diffstat:
3 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/perf-aware-programming/haversine/gen.py b/perf-aware-programming/haversine/gen.py
@@ -78,12 +78,12 @@ print("Avg x: " + str(sum(rndx) / len(rndx)))
print("Avg y: " + str(sum(rndy) / len(rndy)))
hvS = str(hav)
-with open('artifacts/results.txt', 'w') as f:
+with open(args.filepath + ".txt", 'w') as f:
f.writelines([hvS])
h = hashlib.new('sha256')
h.update(hvS.encode())
print(h.hexdigest())
-with open('artifacts/sha.txt', 'w') as f:
+with open(args.filepath + ".sha.txt", 'w') as f:
f.writelines([str(h.hexdigest())])
diff --git a/perf-aware-programming/haversine/json.c b/perf-aware-programming/haversine/json.c
@@ -3,10 +3,10 @@
#include <stdlib.h>
struct Coordinates {
- float x0;
- float x1;
- float y0;
- float y1;
+ double x0;
+ double x1;
+ double y0;
+ double y1;
};
struct Json {
@@ -35,7 +35,7 @@ int isFloatNumeric(char ch) {
}
// idxStart must be first character of the number
-float loadNextNumber(char* jsonStr, int idxStart) {
+double loadNextNumber(char* jsonStr, int idxStart) {
char chars[100];
int idx = 0;
while(isFloatNumeric(jsonStr[idx+idxStart])) {
@@ -43,7 +43,7 @@ float loadNextNumber(char* jsonStr, int idxStart) {
idx += 1;
}
chars[idx+1] = '\0';
- float num = atof(chars);
+ double num = atof(chars);
return num;
}
@@ -97,7 +97,7 @@ struct Coordinates* parseCoordinates(char* jsonData, int* sz) {
continue;
}
if(next == '0' || next == '1') {
- float num = loadNextNumber(jsonData,i+5);
+ double num = loadNextNumber(jsonData,i+5);
if(next == '0' && onX == 1) {
current->x0 = num;
diff --git a/perf-aware-programming/haversine/main.c b/perf-aware-programming/haversine/main.c
@@ -6,8 +6,10 @@ int main(int argc, char** argv) {
printf("Usage: hav {json-filepath}\n");
return -1;
}
+
int size = 0;
struct Coordinates* coords = loadJson(argv[1], &size);
+
if(coords == NULL) {
return -1;
}