Skip to content

Instantly share code, notes, and snippets.

@mstoykov
Created November 1, 2022 08:18
Show Gist options
  • Save mstoykov/5a4aa0e920eb25a6f5ca632ec2f3fefa to your computer and use it in GitHub Desktop.
Save mstoykov/5a4aa0e920eb25a6f5ca632ec2f3fefa to your computer and use it in GitHub Desktop.
Small helper function making a json object into a map of sharedArrays - no checks that this will work are made
import { SharedArray } from "k6/data";
export function mapOfSharedArrays(file) {
let result = {};
let wholeFile;
let populateMap = () => {
if (wholeFile != null) { return; }
wholeFile = JSON.parse(open(file));
}
var keys = new SharedArray(file + "/keys", () => {
populateMap()
return Object.keys(wholeFile);
})
for (let i = 0; i < keys.length; i++) {
result[keys[i]] = new SharedArray(keys[i], function() {
populateMap()
return wholeFile[keys[i]];
});
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment