mirror of
https://github.com/simdjson/simdjson
synced 2026-06-08 17:27:07 +00:00
saving.
This commit is contained in:
+2
-5
@@ -40,16 +40,13 @@ void bench_reflect_cpp(CitmCatalog &data) {
|
||||
|
||||
void bench_rust(serde_benchmark::CitmCatalog *data) {
|
||||
serde_benchmark::set_citm_data(data);
|
||||
char * output = serde_benchmark::serialize_citm_to_string();
|
||||
size_t output_volume = strlen(output);
|
||||
size_t output_volume = serde_benchmark::serialize_citm_to_string();
|
||||
printf("# output volume: %zu bytes\n", output_volume);
|
||||
serde_benchmark::free_str(output);
|
||||
|
||||
volatile size_t measured_volume = 0;
|
||||
pretty_print(1, output_volume, "bench_rust",
|
||||
bench([&measured_volume, &output_volume]() {
|
||||
char * output = serde_benchmark::serialize_citm_to_string();
|
||||
serde_benchmark::free_str(output);
|
||||
measured_volume = serde_benchmark::serialize_citm_to_string();
|
||||
}));
|
||||
}
|
||||
#endif // SIMDJSON_RUST_VERSION
|
||||
|
||||
@@ -38,7 +38,6 @@ pub struct Status {
|
||||
pub struct TwitterData {
|
||||
statuses: Vec<Status>,
|
||||
}
|
||||
|
||||
static mut TWITTER_DATA: *mut TwitterData = std::ptr::null_mut();
|
||||
|
||||
#[no_mangle]
|
||||
@@ -56,13 +55,12 @@ pub unsafe extern "C" fn set_twitter_data(raw: *mut TwitterData) {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn serialize_twitter_to_string() -> *const c_char {
|
||||
pub unsafe extern "C" fn serialize_twitter_to_string() -> usize {
|
||||
if TWITTER_DATA.is_null() {
|
||||
return std::ptr::null();
|
||||
return 0;
|
||||
}
|
||||
let data = &*TWITTER_DATA;
|
||||
let serialized = serde_json::to_string(data).unwrap();
|
||||
std::ffi::CString::new(serialized).unwrap().into_raw() as *const c_char
|
||||
serde_json::to_string(data).unwrap().len()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -214,13 +212,12 @@ pub unsafe extern "C" fn set_citm_data(raw: *mut CitmCatalog) {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn serialize_citm_to_string() -> *mut c_char {
|
||||
pub unsafe extern "C" fn serialize_citm_to_string() -> usize {
|
||||
if CITM_DATA.is_null() {
|
||||
return std::ptr::null_mut();
|
||||
return 0;
|
||||
}
|
||||
let data = &*CITM_DATA;
|
||||
let serialized = serde_json::to_string(data).unwrap();
|
||||
std::ffi::CString::new(serialized).unwrap().into_raw()
|
||||
return serde_json::to_string(data).unwrap().len();
|
||||
}
|
||||
|
||||
/// Frees the CitmCatalog pointer.
|
||||
|
||||
@@ -36,7 +36,7 @@ TwitterData *twitter_from_str(const char *raw_input, size_t raw_input_length);
|
||||
|
||||
void set_twitter_data(TwitterData *raw);
|
||||
|
||||
const char *serialize_twitter_to_string();
|
||||
size_t serialize_twitter_to_string();
|
||||
|
||||
void free_twitter(TwitterData *raw);
|
||||
|
||||
@@ -47,7 +47,7 @@ CitmCatalog *citm_from_str(const char *raw_input, uintptr_t raw_input_length);
|
||||
|
||||
void set_citm_data(CitmCatalog *raw);
|
||||
|
||||
char *serialize_citm_to_string();
|
||||
size_t serialize_citm_to_string();
|
||||
|
||||
/// Frees the CitmCatalog pointer.
|
||||
void free_citm(CitmCatalog *raw_catalog);
|
||||
|
||||
@@ -40,16 +40,13 @@ void bench_reflect_cpp(TwitterData &data) {
|
||||
|
||||
void bench_rust(serde_benchmark::TwitterData *data) {
|
||||
serde_benchmark::set_twitter_data(data);
|
||||
const char * output = serde_benchmark::serialize_twitter_to_string();
|
||||
size_t output_volume = strlen(output);
|
||||
size_t output_volume = serde_benchmark::serialize_twitter_to_string();
|
||||
printf("# output volume: %zu bytes\n", output_volume);
|
||||
serde_benchmark::free_string(output);
|
||||
|
||||
volatile size_t measured_volume = 0;
|
||||
pretty_print(1, output_volume, "bench_rust",
|
||||
bench([&measured_volume, &output_volume]() {
|
||||
const char * output = serde_benchmark::serialize_twitter_to_string();
|
||||
serde_benchmark::free_string(output);
|
||||
measured_volume = serde_benchmark::serialize_twitter_to_string();
|
||||
}));
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user