- Improvements on get method performance#14
Closed
sergiosvieira wants to merge 1 commit intouestla:masterfrom
Closed
- Improvements on get method performance#14sergiosvieira wants to merge 1 commit intouestla:masterfrom
sergiosvieira wants to merge 1 commit intouestla:masterfrom
Conversation
Owner
|
Thank you, that is an interesting insight! Looks like the method The main difference between those two approaches is that the And because the slow method If you won't mind, I won't merge directly your changes here but commit my own replacement and mention you in the commit message ;-) |
Author
|
Sure, no problem 😜
Em sex, 16 de fev de 2018 às 20:57, Petr Kessler <notifications@github.com>
escreveu:
Thank you, that is an interesting insight!
Looks like the method std::vector::at() is terribly slow and just
replacing it with operator[] speeded up your test ~10 times on my machine.
The main difference between those two approaches is that the operator[]
does not check for out-of-range indexes - that is no problem in our case
because we're always checking that given coordinates are valid (method
validateCoordinates()).
And because the slow method at() is being called almost everywhere,
replacing it with [] access speeded up every operation!
If you won't mind, I won't merge directly your changes here but commit my
own replacement and mention you in the commit message ;-)
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAJuuouNury2rCoNCnl3GxGA3OFEHzr1ks5tVhXegaJpZM4SIvWb>
.
--
*Sérgio Vieira*
Master in Computer Science
State University of Ceará (UECE)
|
uestla
added a commit
that referenced
this pull request
Feb 17, 2018
This replaces calling std::vector::at() with direct operator[] access Out-of-range access is prevented thanks to validateCoordinates() method
uestla
added a commit
that referenced
this pull request
Feb 17, 2018
This replaces calling std::vector::at() with direct operator[] access. It is somehow faster - maybe compiler-related optimization or lack of out-of-range checking when using operator[]. Out-of-range access is prevented thanks to validateCoordinates() method
uestla
added a commit
that referenced
this pull request
Feb 17, 2018
This replaces calling std::vector::at() with direct operator[] access. It is somehow faster - maybe compiler-related optimization or lack of out-of-range checking when using operator[]. Out-of-range access is prevented thanks to validateCoordinates() method
uestla
added a commit
that referenced
this pull request
Feb 22, 2018
This replaces calling std::vector::at() with direct operator[] access. It is somehow faster - maybe compiler-related optimization or lack of out-of-range checking when using operator[]. Out-of-range access is prevented thanks to validateCoordinates() method
uestla
added a commit
that referenced
this pull request
Feb 22, 2018
This replaces calling std::vector::at() with direct operator[] access. It is somehow faster - maybe compiler-related optimization or lack of out-of-range checking when using operator[]. Out-of-range access is prevented thanks to validateCoordinates() method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi,
I get some improvements on get access method performance.
In my tests, I used a 1000x1000 matrix and I have made two loops to access each element.
void testInternalAccess(void)
{
SparseMatrix matrix(1000, 1000);
fillRandomMatrix(matrix);
high_resolution_clock::time_point t1 = high_resolution_clock::now();
for (int row = 1; row <= matrix.getRowCount(); ++row)
{
for (int col = 1; col <= matrix.getColumnCount(); ++col)
{
matrix.get(row, col);
}
}
high_resolution_clock::time_point t2 = high_resolution_clock::now();
duration timeSpan = duration_cast<duration>(t2 - t1);
std::cout << "Access matrix values " << timeSpan.count() << " seconds.\n";
}
Test Results
From 5.64532 to 1.22307 seconds.