Benchmarking Results

Computational Resources

All benchmarks were performed on the same machine to ensure consistent comparisons.

  • CPU: Apple M4
  • Number of Cores: 10
  • Memory: 16GB RAM
  • Operating System: macOS Tahoe 26.5.1
  • Julia Version: 1.12.6
  • R Version: 4.4.2

Benchmarking Methods

To assess the efficiency of MetaCommunityMetrics compared to equivalent R implementations, we benchmark our functions against their R counterparts, focusing on execution time and memory usage. The following tables summarize the benchmark results based on 100 samples each.

We tested using datasets of three sizes:

  • Large (53,352 observations)
  • Medium (26,676 observations, 50% of the size of the large dataset)
  • Small (5,325 observations, 10% of the size of the large dataset)

The large dataset is the sample data included with MetaCommunityMetrics, accessible via load_sample_data(). The small and medium datasets can be accessed here.

Each function was benchmarked using 100 samples in both BenchmarkTools.jl in Julia and bench::mark() in R to ensure robust statistical sampling. For memory usage comparisons:

  • In Julia, we report the memory estimate from BenchmarkTools.jl, which measures bytes allocated for a given expression per sample.

  • In R, we report the mem_alloc metric from bench::mark(), which tracks R heap allocation per sample.

According to documentation, the Julia metric measures total memory allocation during execution, while the R metric specifically tracks heap allocations within the R runtime, excluding "memory allocated outside the R heap, e.g., by malloc() or new directly." Due to differences in language implementation and measurement methodology, direct numerical comparisons between languages should be interpreted with caution.

Speedup Summary

Below is a plot showing the speedup of all benchmarked functions across the three datasets (small, medium and large). Speedup is calculated as the R median execution time divided by the Julia median execution time. Median speedup and its confidence interval of each comparison is shown. The grey dashed line shows where speedup equals to 1, that is both R and Julia's implementations require the same amount of time. The calcualation of beta diversity has two variants: quant = true (abundance data is used) and quant = false (occurence data is used). Speedup Plot

Benchmarking Results in Details

All times are in millisecond (ms), and memory is in mebibytes (MiB). All values are rounded up to 4 decimal places.

Median Execution Time and Speedup Values

Bold text indicates the test cases with maximum and minimum speedup values. 95% confidence interval of the speedup is reported.

TestCaseData SizeJuliaRSpeedupLower_CIUpper_CI
Beta Diversity (Abundance, quant=true)Large0.18632.417412.979411.695814.2074
Beta Diversity (Abundance, quant=true)Medium0.11441.365511.939011.177612.5024
Beta Diversity (Abundance, quant=true)Small0.05941.152519.390618.714120.9569
Beta Diversity (Abundance, quant=false)Large0.01780.209611.782410.999012.5062
Beta Diversity (Abundance, quant=false)Medium0.01020.275626.993325.272428.0900
Beta Diversity (Abundance, quant=false)Small0.00630.321950.999147.862353.8532
Beta Diversity (Presence, quant=false)Large0.01640.210112.812312.503113.2637
Beta Diversity (Presence, quant=false)Medium0.01070.309028.974127.773429.8705
Beta Diversity (Presence, quant=false)Small0.00640.330051.766149.142157.7312
Spatial Beta Diversity (Abundance, quant=true)Large2.86669.26703.23273.17273.2908
Spatial Beta Diversity (Abundance, quant=true)Medium2.53199.20433.63543.56123.7110
Spatial Beta Diversity (Abundance, quant=true)Small2.23228.84483.96243.75954.0601
Spatial Beta Diversity (Abundance, quant=false)Large2.58216.97152.69992.64792.7323
Spatial Beta Diversity (Abundance, quant=false)Medium2.25947.16753.17233.10813.2173
Spatial Beta Diversity (Abundance, quant=false)Small1.94956.74693.46073.36093.5694
Spatial Beta Diversity (Presence, quant=false)Large2.55896.96382.72142.68542.7404
Spatial Beta Diversity (Presence, quant=false)Medium2.11917.21823.40633.36073.4530
Spatial Beta Diversity (Presence, quant=false)Small2.13486.69723.13723.06223.3289
Temporal Beta Diversity (Abundance, quant=true)Large8.461753.30166.29916.14736.4106
Temporal Beta Diversity (Abundance, quant=true)Medium7.594854.32087.15236.85327.2299
Temporal Beta Diversity (Abundance, quant=true)Small6.864152.53427.65357.46327.8143
Temporal Beta Diversity (Abundance, quant=false)Large3.67609.76902.65752.62702.7049
Temporal Beta Diversity (Abundance, quant=false)Medium2.98939.67203.23563.18373.3087
Temporal Beta Diversity (Abundance, quant=false)Small2.60749.01863.45883.35463.6131
Temporal Beta Diversity (Presence, quant=false)Large3.62279.38992.59202.56012.6217
Temporal Beta Diversity (Presence, quant=false)Medium3.03029.62863.17753.13213.2545
Temporal Beta Diversity (Presence, quant=false)Small2.63689.02063.42103.28043.5372
Dispersal-niche continuum indexLarge561.078912894.323222.981322.819323.1827
Dispersal-niche continuum indexMedium584.930112608.520821.555621.390821.6751
Dispersal-niche continuum indexSmall102.69793376.087932.874032.594833.2254
Occupied Patches ProportionLarge1.31658.58936.52416.27726.7625
Occupied Patches ProportionMedium1.03428.35068.07447.81708.4617
Occupied Patches ProportionSmall0.70517.908611.216910.540011.8917
Variability MetricsLarge24.1228103.59604.29454.16125.3441
Variability MetricsMedium13.743452.27723.80383.76373.8944
Variability MetricsSmall4.817614.07892.92242.90002.9532
Hypervolume EstimationLarge0.00740.03074.13764.01534.2168
Hypervolume EstimationMedium0.00630.02644.16894.10264.2160
Hypervolume EstimationSmall0.00570.02664.64424.56664.7135
Hypervolume DissimilarityLarge0.01110.139512.587112.338112.9448
Hypervolume DissimilarityMedium0.00990.110911.203511.078111.3024
Hypervolume DissimilaritySmall0.00940.112511.947511.866412.0703

Memory Usage

Benchmarked using Large Dataset

Bold text indicates the test case with the biggest memory usage difference between Julia and R.

TestCaseJuliaR
Beta Diversity (Abundance, quant=true)0.43950.3757
Beta Diversity (Abundance, quant=false)0.08430.1252
Beta Diversity (Presence, quant=false)0.08430.1252
Spatial Beta Diversity (Abundance, quant=true)4.02044.1093
Spatial Beta Diversity (Abundance, quant=false)3.56142.6637
Spatial Beta Diversity (Presence, quant=false)3.56142.6637
Temporal Beta Diversity (Abundance, quant=true)17.081716.8787
Temporal Beta Diversity (Abundance, quant=false)5.81825.1676
Temporal Beta Diversity (Presence, quant=false)5.81825.1676
Dispersal-niche continuum index127.523477.7877
Occupied Patches Proportion1.97961.9928
Variability Metrics12.606160.2264
Hypervolume Estimation0.01180.0022
Hypervolume Dissimilarity0.01980.0145

Benchmarked using Medium Dataset

The test case with the biggest memory usage difference between Julia and R is highligthed.

TestCaseJuliaR
Beta Diversity (Abundance, quant=true)0.25070.0357
Beta Diversity (Abundance, quant=false)0.05200.0798
Beta Diversity (Presence, quant=false)0.05200.0798
Spatial Beta Diversity (Abundance, quant=true)2.48642.2737
Spatial Beta Diversity (Abundance, quant=false)2.03021.8307
Spatial Beta Diversity (Presence, quant=false)2.03021.8307
Temporal Beta Diversity (Abundance, quant=true)15.470616.2510
Temporal Beta Diversity (Abundance, quant=false)4.28704.5399
Temporal Beta Diversity (Presence, quant=false)4.28704.5399
Dispersal-niche continuum index98.497159.2854
Occupied Patches Proportion1.05771.3995
Variability Metrics7.816932.5536
Hypervolume Estimation0.00810.0011
Hypervolume Dissimilarity0.01450.0077

Benchmarked using Small Dataset

The test case with the biggest memory usage difference between Julia and R is highligthed.

TestCaseJuliaR
Beta Diversity (Abundance, quant=true)0.12170.0195
Beta Diversity (Abundance, quant=false)0.02760.0444
Beta Diversity (Presence, quant=false)0.02760.0444
Spatial Beta Diversity (Abundance, quant=true)1.16051.2127
Spatial Beta Diversity (Abundance, quant=false)0.73420.7697
Spatial Beta Diversity (Presence, quant=false)0.73420.7697
Temporal Beta Diversity (Abundance, quant=true)13.060115.4342
Temporal Beta Diversity (Abundance, quant=false)3.05053.7231
Temporal Beta Diversity (Presence, quant=false)3.05053.7231
Dispersal-niche continuum index41.743411.1107
Occupied Patches Proportion0.28430.4932
Variability Metrics3.959010.5805
Hypervolume Estimation0.00550.0003
Hypervolume Dissimilarity0.01080.0014

Datasets used for this benchmark

Large Dataset

53352×12 DataFrame
   Row │ Year   Month  Day    Sampling_date_order  plot   Species  Abundance  Presence  Latitude  Longitude  standardized_temperature  standardized_precipitation 
       │ Int64  Int64  Int64  Int64                Int64  String3  Int64      Int64     Float64   Float64    Float64                 Float64                  
───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
     1 │  2010      1     16                    1      1  BA               0         0      35.0     -110.0                0.829467              -1.4024
     2 │  2010      1     16                    1      2  BA               0         0      35.0     -109.5               -1.12294               -0.0519895
     3 │  2010      1     16                    1      4  BA               0         0      35.0     -108.5               -0.409808              -0.803663
     4 │  2010      1     16                    1      8  BA               0         0      35.5     -109.5               -1.35913               -0.646369
     5 │  2010      1     16                    1      9  BA               0         0      35.5     -109.0                0.0822                 1.09485
   ⋮   │   ⋮      ⋮      ⋮             ⋮             ⋮       ⋮         ⋮         ⋮         ⋮          ⋮                ⋮                        ⋮
 53348 │  2023      3     21                  117      9  SH               0         0      35.5     -109.0               -0.571565              -0.836345
 53349 │  2023      3     21                  117     10  SH               0         0      35.5     -108.5               -2.33729               -0.398522
 53350 │  2023      3     21                  117     12  SH               1         1      35.5     -107.5                0.547169               1.03257
 53351 │  2023      3     21                  117     16  SH               0         0      36.0     -108.5               -0.815015               0.95971
 53352 │  2023      3     21                  117     23  SH               0         0      36.5     -108.0                0.48949               -1.59416
                                                                                                                                            53342 rows omitted

Medium Dataset

26676×12 DataFrame
   Row │ Year   Month  Day    Sampling_date_order  plot   Species  Abundance  Presence  Latitude  Longitude  standardized_temperature  standardized_precipitation 
       │ Int64  Int64  Int64  Int64                Int64  String3  Int64      Int64     Float64   Float64    Float64                 Float64                  
───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
     1 │  2015      7     18                   56     12  PM               0         0      35.5     -107.5              -1.30965                  0.967859
     2 │  2016      8      6                   66     13  SF               0         0      36.0     -110.0               1.45692                  1.77253
     3 │  2017      2     25                   71     21  SF               0         0      36.5     -109.0              -1.50086                  0.993311
     4 │  2018      5     19                   82     16  PB               0         0      36.0     -108.5              -1.2202                   0.684295
   ⋮   │   ⋮      ⋮      ⋮             ⋮             ⋮       ⋮         ⋮         ⋮         ⋮          ⋮                ⋮                        ⋮
 26673 │  2010     11      6                    8     13  BA               0         0      36.0     -110.0              -1.05336                 -0.250324
 26674 │  2013      9     14                   36     12  NA               0         0      35.5     -107.5               0.213222                 0.12
 26675 │  2023      2     18                  116     12  DS               0         0      35.5     -107.5              -0.217475                 0.042571
 26676 │  2014     11     22                   49     13  PF               0         0      36.0     -110.0               0.613491                -1.17076
                                                                                                                                            26668 rows omitted

Small Dataset

5335×12 DataFrame
  Row │ Year   Month  Day    Sampling_date_order  plot   Species  Abundance  Presence  Latitude  Longitude  standardized_temperature  standardized_precipitation 
      │ Int64  Int64  Int64  Int64                Int64  String3  Int64      Int64     Float64   Float64    Float64                 Float64                  
──────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
    1 │  2015      7     18                   56     12  PM               0         0      35.5     -107.5               -1.30965                 0.967859
    2 │  2016      8      6                   66     13  SF               0         0      36.0     -110.0                1.45692                 1.77253
    3 │  2017      2     25                   71     21  SF               0         0      36.5     -109.0               -1.50086                 0.993311
    4 │  2018      5     19                   82     16  PB               0         0      36.0     -108.5               -1.2202                  0.684295
  ⋮   │   ⋮      ⋮      ⋮             ⋮             ⋮       ⋮         ⋮         ⋮         ⋮          ⋮                ⋮                        ⋮
 5332 │  2013     11      2                   37     13  RF               0         0      36.0     -110.0                2.07639                 2.72841
 5333 │  2018     11     10                   88      6  PH               0         0      35.0     -107.5               -0.197006                0.842547
 5334 │  2018      3     24                   80      2  DS               0         0      35.0     -109.5               -0.920093               -0.276074
 5335 │  2014      4     26                   42      7  PH               0         0      35.5     -110.0                0.848755               -0.247144
                                                                                                                                            5327 rows omitted

Remarks

  • For DNCI_multigroup_result, 100 permutations per sample are used in both the Julia and R implementation, and parallelComputing was set to be TRUE when benchmarking DNCImper:::DNCI_multigroup() in R. This means the R implementation distributes permutations across multiple cores, reducing the peak memory footprint per core, which likely contributes to the substantially lower memory usage reported for R compared to Julia. Additionally, direct memory comparisons should be interpreted with caution as Julia reports total memory allocated during execution while R only tracks heap allocations.

The Scripts Used for Benchmarking

Packages used for benchmarking