This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Uses a sorted slice `data: &[E]` as a kind of "multi-map". The | |
/// `key_fn` extracts a key of type `K` from the data, and this | |
/// function finds the range of elements that match the key. `data` | |
/// must have been sorted as if by a call to `sort_by_key` for this to | |
/// work. | |
pub fn binary_search_slice<'d, E, K>(data: &'d [E], key_fn: impl Fn(&E) -> K, key: &K) -> &'d [E] | |
where | |
K: Ord, | |
{ | |
let Ok(mid) = data.binary_search_by_key(key, &key_fn) else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use criterion::{criterion_group, criterion_main, Criterion}; | |
/// Uses a sorted slice `data: &[E]` as a kind of "multi-map". The | |
/// `key_fn` extracts a key of type `K` from the data, and this | |
/// function finds the range of elements that match the key. `data` | |
/// must have been sorted as if by a call to `sort_by_key` for this to | |
/// work. | |
pub fn binary_search_slice<'d, E, K>(data: &'d [E], key_fn: impl Fn(&E) -> K, key: &K) -> &'d [E] | |
where | |
K: Ord, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/compiler/rustc_data_structures/src/binary_search_util/mod.rs b/compiler/rustc_data_structures/src/binary_search_util/mod.rs | |
index d40172a2e2f..c6e3354025a 100644 | |
--- a/compiler/rustc_data_structures/src/binary_search_util/mod.rs | |
+++ b/compiler/rustc_data_structures/src/binary_search_util/mod.rs | |
@@ -10,59 +10,22 @@ pub fn binary_search_slice<'d, E, K>(data: &'d [E], key_fn: impl Fn(&E) -> K, ke | |
where | |
K: Ord, | |
{ | |
- let Ok(mid) = data.binary_search_by_key(key, &key_fn) else { | |
+ let size = data.len(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <numeric> | |
int midpointb(int l, int r) { | |
return (l + r) >> 1; | |
} | |
int midpointw(int l, int r) { | |
return l + (r - l) / 2; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int midpointb(int l, int r) { | |
return (l + r) >> 1; | |
} | |
int midpointw(int l, int r) { | |
return l + (r - l) / 2; | |
} | |
int midpoint(int l, int r) { | |
return static_cast<unsigned int>(l + r) >> 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(core_intrinsics)] | |
use std::intrinsics::fadd_fast; | |
use criterion::{criterion_group, criterion_main, Criterion}; | |
const XS: &'static [f32] = &[3.14; 1000]; | |
fn slow_sum(xs: &[f32]) -> f32 { | |
xs.iter().sum() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <functional> | |
int fact_std_func(int n) { | |
std::function<int(int)> fact = [&](auto n) { | |
if (n == 1) return 1; | |
return n * fact(n-1); | |
}; | |
return fact(n); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"embed" | |
"io/ioutil" | |
"testing" | |
) | |
//go:embed citadel_of_the_star_lords.txt | |
var f embed.FS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <numeric> | |
#include <vector> | |
#include <execution> | |
const int N = 1000000; | |
std::vector<double> xs(N, 1.1); | |
std::vector<double> ys(N, 1.1); | |
double inner_product_1(const std::vector<double>& xs, const std::vector<double>& ys) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
using namespace std; | |
struct Record1 { | |
int a; | |
char c; | |
double d; | |
bool e; | |
}; |