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 map #101

Merged
merged 1 commit into from
Aug 15, 2020
Merged

Reduce calls to malloc in map #101

merged 1 commit into from
Aug 15, 2020

Conversation

bkthomps
Copy link
Owner

@bkthomps bkthomps commented Aug 15, 2020

Using this function for testing:

    map me = map_init(sizeof(int), sizeof(double), compare_int);
    int count = 0;
    int i;
    for (i = 0; i < 1000000; i++) {
        double number = i + 0.5;
        map_put(me, &i, &number);
    }
    for (i = 0; i < 1000000; i++) {
        double get;
        map_get(&get, me, &i);
        assert(get < i + 0.6);
        assert(get > i + 0.4);
        count += map_contains(me, &i);
    }
    printf("%d\n", count);
    map_destroy(me);

The old version would take 0.97s and the new version takes 0.6s. 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 Report

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

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #101   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           16        16           
  Lines         2741      2763   +22     
=========================================
+ Hits          2741      2763   +22     
Impacted Files Coverage Δ
src/map.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 ac725ef...0f96227. Read the comment docs.

@bkthomps bkthomps merged commit fd3d3fc into master Aug 15, 2020
@bkthomps bkthomps deleted the reduce-malloc-calls-map branch August 15, 2020 06:44
This was referenced Aug 15, 2020
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.

None yet

2 participants