File: task_local.rs

package info (click to toggle)
rust-async-std 1.13.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,992 kB
  • sloc: sh: 13; makefile: 8
file content (20 lines) | stat: -rw-r--r-- 330 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#![feature(test)]

extern crate test;

use async_std::task;
use async_std::task_local;
use test::{black_box, Bencher};

#[bench]
fn get(b: &mut Bencher) {
    task_local! {
        static VAL: u64 = 1;
    }

    let mut sum = 0;
    task::block_on(async {
        b.iter(|| VAL.with(|v| sum += v));
    });
    black_box(sum);
}