in reply to Adjusting variable context when workign with JSON data?
I also saw a video about how the JSON module in Perl is quite slow, could that be it?
No, because you are not using the JSON module, you are using the JSON::XS module. The two are quite different and the latter is purposely much faster than the former. And even if it weren't we are not talking about a particularly large chunk of JSON to decode.
I have not profiled your Perl code because as posted it fails to compile:
Missing right curly or square bracket at 11162986.pl line 36, at end o +f line syntax error at 11162986.pl line 36, at EOF 11162986.pl had compilation errors.
While I can guess what is wrong, this shows that the code you have posted is not the code you are running, so who knows what else might actually be in there to slow it down.
Regardless, a fair guess would be that the slow part is this line:
my $result = qx{ i3-msg -t get_workspaces }; # returns [{},{},{}]
Shelling out 100 times is going to be slow however you do it. Try obtaining the JSON once and then loop 100 times over the rest of the processing and see what difference that makes.
🦛
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Adjusting variable context when working with JSON data?
by unmatched (Sexton) on Dec 03, 2024 at 21:31 UTC | |
by choroba (Cardinal) on Dec 03, 2024 at 21:38 UTC | |
by unmatched (Sexton) on Dec 04, 2024 at 17:24 UTC | |
by Danny (Chaplain) on Dec 05, 2024 at 00:57 UTC | |
by unmatched (Sexton) on Dec 08, 2024 at 10:52 UTC | |
by hippo (Archbishop) on Dec 08, 2024 at 11:32 UTC | |
by unmatched (Sexton) on Dec 09, 2024 at 10:56 UTC | |
|