-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Description
Platform: Windows 10
go version go1.12.4 windows/amd64
node version v8.11.1
Maybe there is some problem with my usage?
code is here:
package main
import (
"fmt"
"time"
"github.com/360EntSecGroup-Skylar/excelize"
)
func main() {
excelPath := "data.xlsx"
timeStart := time.Now().UTC().UnixNano() / 1e6
times := 5
for i :=0 ; i < times; i++ {
f, _ := excelize.OpenFile(excelPath)
_, _ = f.GetRows("main")
}
timeFinished := time.Now().UTC().UnixNano() / 1e6
fmt.Println(timeFinished - timeStart)
}
import * as XLSX from 'xlsx';
function run() {
let currentMilliSec = Date.now()
let times = 5
let excelPath = "data.xlsx"
for (let i = 0; i < times; i++) {
var workbook = XLSX.readFile(excelPath);
let sheet = workbook.Sheets["main"];
// let ref: string = sheet['!ref'];
// console.log(ref);
// let xx = ref.split(':')
// console.log(xx[0], xx[1]);
// let start = XLSX.utils.decode_cell(xx[0]);
// console.log(start.c, start.r, XLSX.utils.encode_cell(start));
// let end = XLSX.utils.decode_cell(xx[1]);
// console.log(end.c, end.r, XLSX.utils.encode_cell(end));
// let starRowIdx = 0
// for (let r = 0; r <= end.r; r++) {
// let cellName = XLSX.utils.encode_cell({ c: 0, r: r });
// let cell = sheet[cellName]
// }
}
let after = Date.now()
console.log("js cost: ", after - currentMilliSec, "ms")
}
run()
Activity
mlh758 commentedon Jul 20, 2019
Does
worksbook.Sheets["main"]
actually parse and read each row?GetRows
does, it looks like you have the actual reading code commented out on the JS tests there.xtutu commentedon Jul 22, 2019
Actually
Because even I uncomment the original code, Time Cost Not Changed !
@mlh758
mlh758 commentedon Jul 23, 2019
I’ll have to try the benchmarks out. We’ve had a few passes to improve the performance of the library but there is probably plenty of work that could be done as a community. Using Go benchmarks and the profiler could help highlight the slowest areas.
Also, many Node libraries are hooked up to some pretty efficient C libraries under the hood.
mlh758 commentedon Jul 31, 2019
I had a pretty big excel file on hand so I went ahead and tried things out, here are my benchmark files:
The go example ran in 17 seconds, the js example ran in 20 seconds, which puts them at roughly even. If I use
GetRows
like you did in your benchmarks the Go code runs up to 25 seconds. Seems likeRows
is much more efficient to use.mlh758 commentedon Jul 31, 2019
I just noticed I ran the benchmarks against 1.4.1. If I switch the import to
"github.com/360EntSecGroup-Skylar/excelize/v2"
and run against 2.0.1 the times don't change much though.mlh758 commentedon Jul 31, 2019
For fun I moved this to a benchmark:
Then ran it with the profilers enabled:
CPU profile results:
Memory:
It looks like the vast majority of our time is spent the standard library's xml decoder.
mlh758 commentedon Jul 31, 2019
For visual reference
mlh758 commentedon Aug 1, 2019
@xtutu sent me the data file he was using for testing. When I use
Rows()
on it I get a segfault from rows.go line 106. Not sure what's going on there yet, but we almost certainly have a bug.Edit: Nope, typo on my part. Wasn't checking the errors since it was a benchmark. Library is fine.
Merge pull request #456 from mlh758/fix-439
Only parse xml once when reading
Merge pull request qax-os#456 from mlh758/fix-439
Further improve read performance