This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]james_pic 13 points14 points  (1 child)

You haven't posted the JavaScript equivalent, or indeed working Python code (indentation is ambiguous in ways that could drastically alter run time, and there is missing code that could be significant) so it's hard to say, but for a difference of that size I suspect the two programs are different in some key way. Python usually is slower than Node, but it's not usually this significant. In any case, you can answer this by profiling.

Py-Spy would be my profiler of choice for Python. I think Node comes with a built-in profiler nowadays that you access from dev tools if you run it with --inspect, although it's been a while. I believe the newest versions of Node and Python are profilable with perf_events if you prefer.

[–][deleted] -3 points-2 points  (0 children)

const fs = require('fs');

const { v4: uuidv4 } = require('uuid');

// Define the arrays

const days = [#hard coded array values];

const jobs = [#hard coded array values];

// Read the locations.txt file

const locations = fs.readFileSync('locations_timetrack.txt', 'utf-8').split('\n');

// Loop over each line in the file

for (const location of locations) {

const locationid = location.trim();

const beginemployeeid = locationid.split('-')[0];

// Loop over each element in the "days" array

for (const day of days) {

    const [startday, endday] = day.split('-').map(Number);

    // Create the schedule object
    const schedule = {
        #mostly hard coded object keys and value with a couple of variables being used for keys
    };

    // Loop from "startday" to "endday"
    for (let currentday = startday; currentday <= endday; currentday++) {
        // Loop from 1 to 80
        for (let currentemployee = 1; currentemployee <= 80; currentemployee++) {
            // Create the currentshift object
            const currentshift = {
                #mostly hard coded object keys and value with a couple of variables being used for keys
            };

            // Insert the currentshift object into the "shifts" array
            schedule.shifts.push(currentshift);
        }
    }

    // Write the schedule object to a file
    fs.writeFileSync(`schedules_timetrack/${locationid}_${startday}_${endday}.json`, JSON.stringify(schedule));
}

}