Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce calls to malloc in multimap #102

Merged
merged 2 commits into from
Aug 16, 2020
Merged

Conversation

bkthomps
Copy link
Owner

@bkthomps bkthomps commented Aug 15, 2020

Using the following code:

    multimap me = multimap_init(sizeof(int), sizeof(double), compare_int,
                                compare_int);
    int count = 0;
    int i;
    for (i = 0; i < 1000000; i++) {
        int j;
        for (j = 0; j < 5; j++) {
            multimap_put(me, &i, &j);
        }
    }
    for (i = 0; i < 1000000; i++) {
        int j = 0;
        int get;
        multimap_get_start(me, &i);
        while (multimap_get_next(&get, me)) {
            if (get == j) {
                count++;
            }
            j++;
        }
    }
    printf("%d\n", count);
    multimap_destroy(me);

The old version would run in 2.8s and the new version runs in 1.7s. This is an improvement of 40%.

@bkthomps bkthomps added the efficiency Any improvement which can be made to the time or memory usage label Aug 15, 2020
@bkthomps bkthomps self-assigned this Aug 15, 2020
@codecov-commenter
Copy link

codecov-commenter commented Aug 15, 2020

Codecov Report

Merging #102 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #102   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           16        16           
  Lines         2763      2804   +41     
=========================================
+ Hits          2763      2804   +41     
Impacted Files Coverage Δ
src/multimap.c 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fd3d3fc...10c79d7. Read the comment docs.

@bkthomps bkthomps changed the title Update function signatures Reduce calls to malloc in multimap Aug 15, 2020
@bkthomps bkthomps merged commit 5c4752c into master Aug 16, 2020
@bkthomps bkthomps deleted the reduce-malloc-calls-multimap branch August 16, 2020 15:22
This was referenced Aug 16, 2020
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
efficiency Any improvement which can be made to the time or memory usage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants