File: cr_obj_multi.c

package info (click to toggle)
libfastjson 1.2304.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,144 kB
  • sloc: sh: 4,486; ansic: 4,464; makefile: 114
file content (46 lines) | stat: -rw-r--r-- 1,031 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* libfastjson testbench tool
 *
 * Copyright (c) 2016 Adiscon GmbH
 * Rainer Gerhards <rgerhards@adiscon.com>
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the MIT license. See COPYING for details.
 *
 */
#include "config.h"

#include "../json.h"

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

#define NUM_CREATIONS 1000000

int main(int __attribute__((unused)) argc, char __attribute__((unused)) **argv)
{
	int i;
	char pb[64];
	struct fjson_object **json = calloc(NUM_CREATIONS, sizeof(struct fjson_object *));

	if(json == NULL) {
		perror("malloc ptr table failed:");
		exit(1);
	}

	for(i = 0 ; i < NUM_CREATIONS ; ++i) {
		json[i] = fjson_object_new_object();
//fprintf(stderr, "main: json[%d] %p\n", i, json[i]);
		snprintf(pb, sizeof(pb), "%d", i);
		fjson_object_object_add(json[i], pb, fjson_object_new_string(pb));
		
	}

	/* free all objects again */
	for(i = 0 ; i < NUM_CREATIONS ; ++i) {
		fjson_object_put(json[i]);
	}

	free(json);
	return 0;
}