You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

88 lines
1.9 KiB

#include <stdarg.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <cyaml/cyaml.h>
#include "full_project.h"
static const cyaml_config_t config = {
.log_level = CYAML_LOG_WARNING,
.log_fn = cyaml_log,
.mem_fn = cyaml_mem,
};
static const int times_to_test = 5;
static void
serialize (
void * project_ptr)
{
char * output;
size_t output_len;
clock_t before = clock();
for (int i = 0; i < times_to_test; i++)
{
cyaml_err_t err =
cyaml_save_data (
&output, &output_len,
&config, &project_schema, project_ptr, 0);
if (err != CYAML_OK)
{
fprintf (stderr, "Failed to serialize: %s\n", cyaml_strerror (err));
exit (EXIT_FAILURE);
}
}
clock_t difference = clock() - before;
int msec = (difference * 1000 / CLOCKS_PER_SEC) / times_to_test;
fprintf (
stderr,
"Average time to serialize (%d tries, -O%d): %dms\n",
times_to_test, OPTIMIZATION, msec);
}
static void *
deserialize (
const char * filepath)
{
void * obj;
clock_t before = clock();
for (int i = 0; i < times_to_test; i++)
{
cyaml_err_t err =
cyaml_load_file (
filepath,
&config, &project_schema, (cyaml_data_t **) &obj,
NULL);
if (err != CYAML_OK)
{
fprintf (stderr, "Failed to deserialize: %s\n", cyaml_strerror (err));
exit (EXIT_FAILURE);
}
}
clock_t difference = clock() - before;
int msec = (difference * 1000 / CLOCKS_PER_SEC) / times_to_test;
fprintf (
stderr,
"Average time to deserialize (%d tries, -O%d): %dms\n",
times_to_test, OPTIMIZATION, msec);
return obj;
}
int main (
int argc,
char ** argv)
{
if (argc != 2)
{
fprintf (stderr, "%s", "Need 1 argument\n");
exit (EXIT_FAILURE);
}
void * obj = deserialize (argv[1]);
serialize (obj);
return 0;
}