<commit_before>#define _POSIX_C_SOURCE 199309L		/* for clock_gettime() */

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

#include "../include/libbase64.h"
#include "codec_supported.h"

#define INSIZE_MB  10
#define RANDOMDEV  "/dev/urandom"

struct buffers {
	char *reg;
	char *enc;
	size_t regsz;
	size_t encsz;
};

static int
get_random_data (struct buffers *b, char **errmsg)
{
	int fd;
	ssize_t nread;
	size_t total_read = 0;

	/* Open random device for semi-random data: */
	if ((fd = open(RANDOMDEV, O_RDONLY)) < 0) {
		*errmsg = "Cannot open " RANDOMDEV "\n";
		return 0;
	}
	printf("Filling buffer with random data...\n");

	while (total_read < b->regsz) {
		if ((nread = read(fd, b->reg + total_read, b->regsz - total_read)) < 0) {
			*errmsg = "Read error\n";
			close(fd);
			return 0;
		}
		total_read += nread;
	}
	close(fd);
	return 1;
}

static float
timediff_sec (struct timespec *start, struct timespec *end)
{
	return (end->tv_sec - start->tv_sec) + ((float)(end->tv_nsec - start->tv_nsec)) / 1000000000.0f;
}

static void
codec_bench_enc (struct buffers *b, char *const name, unsigned int flags)
{
	int i;
	float timediff, fastest = -1.0f;
	struct timespec start, end;

	/* Choose fastest of ten runs: */
	for (i = 0; i < 10; i++) {
		clock_gettime(CLOCK_REALTIME, &start);
		base64_encode(b->reg, b->regsz, b->enc, &b->encsz, flags);
		clock_gettime(CLOCK_REALTIME, &end);
		timediff = timediff_sec(&start, &end);
		if (fastest < 0.0f || timediff < fastest) {<commit_msg>Benchmark: use scientific notation for large constants<commit_after>#define _POSIX_C_SOURCE 199309L		/* for clock_gettime() */

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

#include "../include/libbase64.h"
#include "codec_supported.h"

#define INSIZE_MB  10
#define RANDOMDEV  "/dev/urandom"

struct buffers {
	char *reg;
	char *enc;
	size_t regsz;
	size_t encsz;
};

static int
get_random_data (struct buffers *b, char **errmsg)
{
	int fd;
	ssize_t nread;
	size_t total_read = 0;

	/* Open random device for semi-random data: */
	if ((fd = open(RANDOMDEV, O_RDONLY)) < 0) {
		*errmsg = "Cannot open " RANDOMDEV "\n";
		return 0;
	}
	printf("Filling buffer with random data...\n");

	while (total_read < b->regsz) {
		if ((nread = read(fd, b->reg + total_read, b->regsz - total_read)) < 0) {
			*errmsg = "Read error\n";
			close(fd);
			return 0;
		}
		total_read += nread;
	}
	close(fd);
	return 1;
}

static float
timediff_sec (struct timespec *start, struct timespec *end)
{
	return (end->tv_sec - start->tv_sec) + ((float)(end->tv_nsec - start->tv_nsec)) / 1e9f;
}

static void
codec_bench_enc (struct buffers *b, char *const name, unsigned int flags)
{
	int i;
	float timediff, fastest = -1.0f;
	struct timespec start, end;

	/* Choose fastest of ten runs: */
	for (i = 0; i < 10; i++) {
		clock_gettime(CLOCK_REALTIME, &start);
		base64_encode(b->reg, b->regsz, b->enc, &b->encsz, flags);
		clock_gettime(CLOCK_REALTIME, &end);
		timediff = timediff_sec(&start, &end);
		if (fastest < 0.0f || timediff < fastest) {
{'fraction_non_alphanumeric': 0.15907673112913287, 'fraction_numerical': 0.019650655021834062, 'mean_word_length': 3.979813664596273, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1728011', 'n_tokens_mistral': 1383, 'n_tokens_neox': 1282, 'n_words': 336}