google benchmark学习与使用

google benchmark

#include <benchmark/benchmark.h>

#include <array>

constexpr int len = 6;

// constexpr function具有inline属性,你应该把它放在头文件中

constexpr auto my_pow(const int i)

{

return i * i;

}

// 使用operator[]读取元素,依次存入1-6的平方

static void bench_array_operator(benchmark::State& state)

{

......

C++11多线程例子

// CPP program to demonstrate multithreading

// using three different callables.

#include <iostream>

#include <thread>

using namespace std;

// A dummy function

void foo(int Z)

{

for (int i = 0; i < Z; i++) {

cout << "Thread using function"

" pointer as callable\n";

}

}

// A ca......

grpc入门教程

周五在家折腾了下grpc,在13年的一个笔记本上编译居然用了8个小时,内存swap用了15G,简直了。

This guide gets you started with gRPC in C++ with a simple working example.

Introduction to gRPC

A basic tutorial introduction to gRPC in C++.

gRPC Crash Course - Modes, Examples, Pros & Cons and more

[LeetCode C++实现]45. 跳跃游戏 II

[LeetCode C++实现]45. 跳跃游戏 II

date:2021-07-12 23:30

url:LeetCode45

class Solution {

public:

int jump(vector<int>& nums) {

int size = nums.size();

int right = 0,step = 0,end = 0;

for(int i = 0;i < size - 1;i++)

{

if(i <= right)

{

right = max(right,i + nums[i]);

if(i == end)

{

end =......

[LeetCode C++实现]55.跳跃游戏

class Solution {

public:

bool canJump(vector<int>& nums) {

int size = nums.size();

int right = 0;

for(int i = 0;i < size;i++)

{

if(i <= right)

{

right = max(right,i + nums[i]);

if(right >= size - 1)

return true;

}else

return false;

}

return false;

}

};

这道题的思路是贪心,从前往后计算能够到达的最远距......

[LeetCode C++实现]179. Largest Number

讨论区看到一个解法,非常的清晰,缺点是需要构造一个vector,因此空间复杂度较高。

class Solution {

public:

string largestNumber(vector<int>& nums) {

vector<string> strs;

for(auto num:nums)

strs.push_back(to_string(num));

sort(strs.begin(),strs.end(),[](const string& s1,const string& s2){return s1 + s2 > s2 +......

Linux添加swap分区,解决内存不足

周末在家打算安装学习下grpc,发现安装到一半oom内存不足,于是有了这篇文章.

Swap 是 Linux 下的交换分区,类似 Windows 的虚拟内存,当物理内存不足时,系统可把一些内存中不常用到的程序放入 Swap,解决物理内存不足的情况。但是如果开始使用 SWAP 的时候系统通常都会变得十分缓慢,因为硬盘 IO 占用的十分厉害,除非是 SSD 的情况下,速度才有可能稍微快一点。

下面是创建使用 SWAP 的方法:

一、创建文件

dd if=/dev/zero of=/swapfile bs=1024 count=8096000

SSH 执行以上命令,创建一个名为 sw......

IDEA快捷键

clion常用快捷键:

command + [ 回退

command + ] 前进

command + O 查找class

shift command + O 查找文件

option command + O 查找符号

git clone慢解决方法

1.在网站 https://www.ipaddress.com/ 上搜索

github.global.ssl.fastly.net

github.com

这两个域名所对应的ip填入/etc/hosts中

2.添加hosts

[root grpc]#cat /etc/hosts

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4

::1 localhost localhost.localdomain localhost6 localhost6.loc......

程序员面试金典-面试题 03.03. 堆盘子

堆盘子。设想有一堆盘子,堆太高可能会倒下来。因此,在现实生活中,盘子堆到一定高度时,我们就会另外堆一堆盘子。请实现数据结构SetOfStacks,模拟这种行为。SetOfStacks应该由多个栈组成,并且在前一个栈填满时新建一个栈。此外,SetOfStacks.push()和SetOfStacks.pop()应该与普通栈的操作方法相同(也就是说,pop()返回的值,应该跟只有一个栈时的情况一样)。 进阶:实现一个popAt(int index)方法,根据指定的子栈,执行pop操作。

当某个栈为空时,应当删除该栈。当栈中没有元素或不存在该栈时,pop,popAt 应返回 -1.

示例1......