Make faster by splitting borrows of byte slice
This commit is contained in:
parent
40a8d6d929
commit
98cd6e930c
@ -2,6 +2,7 @@ use crate::models::station_measurements::StationMeasurements;
|
|||||||
use crate::utils::{hash, parse};
|
use crate::utils::{hash, parse};
|
||||||
use memmap2::MmapOptions;
|
use memmap2::MmapOptions;
|
||||||
use rustc_hash::{FxBuildHasher, FxHashMap as HashMap};
|
use rustc_hash::{FxBuildHasher, FxHashMap as HashMap};
|
||||||
|
use std::slice::from_raw_parts;
|
||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use std::{fs::File, thread};
|
use std::{fs::File, thread};
|
||||||
@ -13,6 +14,7 @@ pub fn run() {
|
|||||||
const FILE_PATH: &str = "../../../measurements.txt";
|
const FILE_PATH: &str = "../../../measurements.txt";
|
||||||
let file = File::open(FILE_PATH).expect("File measurements.txt not found");
|
let file = File::open(FILE_PATH).expect("File measurements.txt not found");
|
||||||
let mmap = unsafe { MmapOptions::new().map(&file).unwrap() };
|
let mmap = unsafe { MmapOptions::new().map(&file).unwrap() };
|
||||||
|
let mmap_ptr = mmap.as_ptr();
|
||||||
let file_length = mmap.len();
|
let file_length = mmap.len();
|
||||||
let hasher = FxBuildHasher;
|
let hasher = FxBuildHasher;
|
||||||
let mut stations: HashMap<u64, (String, StationMeasurements)> =
|
let mut stations: HashMap<u64, (String, StationMeasurements)> =
|
||||||
@ -39,7 +41,7 @@ pub fn run() {
|
|||||||
for i in 0..cores {
|
for i in 0..cores {
|
||||||
let tx = tx.clone();
|
let tx = tx.clone();
|
||||||
let (start, end) = *bounds.get(i).unwrap();
|
let (start, end) = *bounds.get(i).unwrap();
|
||||||
let mmap_slice = &mmap[start..end];
|
let mmap_slice = unsafe { from_raw_parts(mmap_ptr.add(start), end - start) };
|
||||||
s.spawn(move || {
|
s.spawn(move || {
|
||||||
let mut t_stations: HashMap<u64, (String, StationMeasurements)> =
|
let mut t_stations: HashMap<u64, (String, StationMeasurements)> =
|
||||||
HashMap::with_capacity_and_hasher(DEFAULT_HASHMAP_LENGTH, hasher);
|
HashMap::with_capacity_and_hasher(DEFAULT_HASHMAP_LENGTH, hasher);
|
||||||
|
Loading…
Reference in New Issue
Block a user