GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Improve performance of MockExpectedCallsList by mmartalo · Pull Request #778 · cpputest/cpputest

Conversation

@mmartalo

@mmartalo mmartalo commented Aug 23, 2015

Copy link
Copy Markdown

For large number (e.g. 10000) of mocked calls, the simple linked list
was a performance bottleneck.
This patch brings two improvements:

  • tracking the last element of the linked list (for O(1) insertion)
  • deleting NULL elements as they are marked, as opposed to rescanning
    the list from scratch after marking.
    Profiling with callgrind shows that the linked list structure is no
    longer the performance bottleneck.

I know that having a huge number of mocked/expected calls is debatable, but it did happen to matter in my use case. Basically, I'm doing checks of the type: perform an operation, and assert that a certain log message is displayed. This means that MockExpectedCallsList has to scale to the number of logs printed by the operation.

As you see from the Callgrind results for this particular test case, addExpectedCall was spending most of its time in self(). Where the vast majority of this time went was into looping through the linked list in order to find the tail, so that it can insert the new element.

Profiling overview before patch:
callgrind results before patch
Profiling before patch, zoom in on addExpectedCall:
callgrind zoom in on addexpectedcall
Profiling overview after patch:
callgrind results after patch

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mmartalo
Improve performance of MockExpectedCallsList
25b4c51
For large number (e.g. 10000) of mocked calls, the simple linked list
was a performance bottleneck.
This patch brings two improvements:
- tracking the last element of the linked list (for O(1) insertion)
- deleting NULL elements as they are marked, as opposed to rescanning
  the list from scratch after marking.
Profiling with callgrind shows that the linked list structure is no
longer the performance bottleneck.
mmartalo
mmartalo reviewed Aug 23, 2015
View reviewed changes
Comment thread src/CppUTestExt/MockExpectedCallsList.cpp Outdated

@mmartalo mmartalo Aug 23, 2015

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think keeping the iteration algorithm in one place is good, but I'm ok with inlining this everywhere if you find it ugly.

PREV should be changed to PARENT

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mmartalo
Fixed macro naming and using <assert.h>
a00b036
@arstrube

arstrube commented Aug 23, 2015

Copy link
Copy Markdown
Contributor

Great!

Do you suppose you could do the same without using Std C Lib assert()? The thing is that CppUTest shouldn't depend on the Std C library, and the inclusion of assert.h breaks that.

This is why you get a failure on Travis CI - it's a run specifically designed to check for compilation without Std. C library.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mmartalo
No longer using C stdlib assert.h
9fd9856
Asserts left in the code as comments
@mmartalo

mmartalo commented Aug 23, 2015

Copy link
Copy Markdown
Author

Oh ok, I didn't know that. I was wondering how assert.h could be missing :)
I removed the asserts. I left them as comments, I think they help reading the code, but I can remove them completely if they seem overkill.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@arstrube

arstrube commented Aug 23, 2015

Copy link
Copy Markdown
Contributor

There you go. About the comments / asserts, let's see what @basvodde has to say. Looking forward to this being merged....

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mmartalo
Forgot git add after adding back commented asserts
ca9e76c
@mmartalo

mmartalo commented Sep 7, 2015

Copy link
Copy Markdown
Author

Any news on this? If the PR needs changes, please let me know this week, as I'll be unavailable for a couple of weeks afterwards.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@basvodde

basvodde commented Sep 9, 2015

Copy link
Copy Markdown
Member

Sorry! I won't have time to merge it this week, but I'll definitively will request some small changes. That said, I'm pretty sure eventually it'll be merged as this was one problem that needed to be solved. So thanks for that and sorry for the slow response during these days.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@mmartalo @arstrube @basvodde
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.