..
type Row [COL]int32
type Table []Row
func (lst Table) Swap(i, j int) { lst[j], lst[i] = lst[i], lst[j] }
..
is this really what you want? Every swap operation is copying 10000
int32s around.
Your program performance will be dominated by the cost of copying flat
arrays of data.
You could consider storing slices rather than 10000-large arrays.
--
Han-Wen Nienhuys
Google Engineering Belo Horizonte
han...@google.com
You're comparing apples and supernovas. Print a sample of the Python
table. You're iterating 100 times switching rows up and down, without
sorting anything.
> The performance, however, is simply shocking. In
(...)
> I would be glad to see that I made some basic error ...
Be happy then. ;-)
--
Gustavo Niemeyer
http://niemeyer.net
http://niemeyer.net/plus
http://niemeyer.net/twitter
http://niemeyer.net/blog
-- I'm not absolutely sure of anything.
Yes.
More generally the Go program seems to sort the single slice of large
arrays COL times. The Python program seems to sort each each column
independently.
Ian
It's worse than that.. it doesn't even sort the columns. It swaps the
entire rows col times, where col == 100. At the end, rows will be
ordered by the magnitude of the last column element.
You can also take advantage of the way Go allows you to control memory
layout by making the entire table contiguous and thus make better use of
cache.
func NewTable() Table {
tab := Table(make([]Row, 0,ROW))
t := make([]int32,ROW*COL)
for i:=0;i<ROW;i++ {
tab = append(tab,Row(t[i*COL:(i+1)*COL]))
}
return tab
}
http://play.golang.org/p/UFTafXCJAR
And you say "no magic" with a straight face after reading this thread? ;)
Hey,
Thanks for pointing me the thread on golang-nuts, however, I don't
really know what should I reply to that. Do you have any precise
question in mind?
Cheers,
fijal