The first Copilot suggestion--reading a list and then converting the list to an array--seems better. WithIt looks more paradigmatic to me. Unfortunately, the run timeThe statement
Fido opened one eye and typed, "Is there any way to performance optimize the above code?"appears to be a hallucination.Code:
var lines = file.readlines();
indicates the execution speed isCode:
$ ./day01 -nl 1Advent of Code 2024 Day 01 Historian HysteriaPart 1 The total distance between lists is 2000468Part 2 The similarity between lists is 18567089Total execution time 0.006961 seconds.
(0.006961-0.005264)/0.005264 = 32 percent
slower than before.
Code:
proc doinit(){ var io=open("day01.txt",ioMode.r); var fp=io.reader(locking=false); var data=fp.lines(); var idxl,idyl:list(int); var k=0; for s in fp.lines() { k+=1; var v=s.split(); idxl.pushBack(v(0):int); idyl.pushBack(v(1):int); } var idx,idy:[1..k]int; idx=idxl; idy=idyl; var p1=part1(idx,idy); writef("Part 1 The total distance between lists is %i\n",p1); var p2=part2(idx,idy); writef("Part 2 The similarity between lists is %i\n",p2);}
The result
Code:
$ ./day01 -nl 1Advent of Code 2024 Day 01 Historian HysteriaPart 1 The total distance between lists is 0Part 2 The similarity between lists is 0Total execution time 0.002271 seconds.
(0.005264-0.002271)/0.005264 = 58 percent
speedup over the original Chapel code.
Statistics: Posted by ejolson — Tue Dec 03, 2024 8:17 pm