[GH-ISSUE #426] File creation performance #334

Closed
opened 2026-05-05 12:10:15 -06:00 by gitea-mirror · 2 comments
Owner

Originally created by @duncangroenewald on GitHub (Dec 23, 2023).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/426

Originally assigned to: @jmcnamara on GitHub.

Is there any way to improve the performance when creating a file. I am generating a 4.5mb XLS file and the creation process seems to be quite slow - around about a minute - given the size I would expect that could be done much faster than that.

I haven't done much investigation on what exactly could be the cause but it seems to be creation of the cells themselves that is slowing things down.

I figured I would ask just in case there might be some quick way to improve performance.

Thanks

Originally created by @duncangroenewald on GitHub (Dec 23, 2023). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/426 Originally assigned to: @jmcnamara on GitHub. Is there any way to improve the performance when creating a file. I am generating a 4.5mb XLS file and the creation process seems to be quite slow - around about a minute - given the size I would expect that could be done much faster than that. I haven't done much investigation on what exactly could be the cause but it seems to be creation of the cells themselves that is slowing things down. I figured I would ask just in case there might be some quick way to improve performance. Thanks
Author
Owner

@jmcnamara commented on GitHub (Dec 23, 2023):

It shouldn't take anything like a minute to create a 4.5MB file.

Here is a sample program I ran as a test:

#include "xlsxwriter.h"

int main() {

    int max_row = 45000;
    int max_col = 50;

    lxw_workbook  *workbook  = workbook_new("c_perf_test.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);

    for (int row_num = 0; row_num < max_row; row_num++) {
        for (int col_num = 0; col_num < max_col; col_num++) {
            if (col_num % 2)
                worksheet_write_string(worksheet, row_num, col_num, "Foo", NULL);
            else
                worksheet_write_number(worksheet, row_num, col_num, 12345.0, NULL);

        }
    }

    workbook_close(workbook);

    return 0;
}

I put this in the examples directory of a repo clone and compiled it as follows:

make examples

This runs in around 2.5sec:

$ time ./examples/c_perf_test

real	0m2.424s
user	0m1.945s
sys	0m0.311s

And the output file is ~ 4.5MB:

$ ls -lh c_perf_test.xlsx
-rw-r--r--  1 John  staff   4.6M 23 Dec 10:19 c_perf_test.xlsx

This was on a 3.2 GHz 6-Core Intel Core i7 Mac mini with macOS 14.2.1 (Sonoma).

I'd suggest starting with the same example, verifying the performance, and if it is more or less the same then try to figure out what extra work your program is doing.

<!-- gh-comment-id:1868262962 --> @jmcnamara commented on GitHub (Dec 23, 2023): It shouldn't take anything like a minute to create a 4.5MB file. Here is a sample program I ran as a test: ```C #include "xlsxwriter.h" int main() { int max_row = 45000; int max_col = 50; lxw_workbook *workbook = workbook_new("c_perf_test.xlsx"); lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL); for (int row_num = 0; row_num < max_row; row_num++) { for (int col_num = 0; col_num < max_col; col_num++) { if (col_num % 2) worksheet_write_string(worksheet, row_num, col_num, "Foo", NULL); else worksheet_write_number(worksheet, row_num, col_num, 12345.0, NULL); } } workbook_close(workbook); return 0; } ``` I put this in the examples directory of a repo clone and compiled it as follows: ```bash make examples ``` This runs in around 2.5sec: ```bash $ time ./examples/c_perf_test real 0m2.424s user 0m1.945s sys 0m0.311s ``` And the output file is ~ 4.5MB: ```bash $ ls -lh c_perf_test.xlsx -rw-r--r-- 1 John staff 4.6M 23 Dec 10:19 c_perf_test.xlsx ``` This was on a 3.2 GHz 6-Core Intel Core i7 Mac mini with macOS 14.2.1 (Sonoma). I'd suggest starting with the same example, verifying the performance, and if it is more or less the same then try to figure out what extra work your program is doing.
Author
Owner

@duncangroenewald commented on GitHub (Dec 23, 2023):

Thanks for that. I just looked into it a little more and I have to convert values from strings and the checks to determine the value type seem to be slowing things down. Nothing to do with this library.

<!-- gh-comment-id:1868368807 --> @duncangroenewald commented on GitHub (Dec 23, 2023): Thanks for that. I just looked into it a little more and I have to convert values from strings and the checks to determine the value type seem to be slowing things down. Nothing to do with this library.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/libxlsxwriter#334
No description provided.