Skip to content

Commit 7abcc54

Browse files
committed
old
1 parent 56e79dc commit 7abcc54

File tree

21 files changed

+338
-2
lines changed

21 files changed

+338
-2
lines changed

16/00.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <map>
4+
5+
using namespace std;
6+
7+
int main() {
8+
map<string, int> items = {
9+
{"hello", 1},
10+
{"world", 2},
11+
};
12+
13+
items["time"] = 4;
14+
int time = items.at("time");
15+
cout << time << endl;
16+
}

16/00.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
items = dict([
2+
("hello", 1),
3+
("world", 2),
4+
])
5+
6+
items["time"] = 4
7+
time = items["time"]
8+
print(time)

16/00a.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <map>
4+
5+
using namespace std;
6+
7+
int main() {
8+
map<string, int> items = {
9+
{"hello", 1},
10+
{"world", 2},
11+
};
12+
13+
int time = items["hello"];
14+
cout << time << endl;
15+
}

16/00b.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <map>
4+
5+
using namespace std;
6+
7+
int main() {
8+
map<string, int> items = {
9+
{"hello", 1},
10+
{"world", 2},
11+
};
12+
13+
int time = items["hell"];
14+
cout << time << endl;
15+
}

16/01.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <iostream>
2+
#include <map>
3+
#include "printer.h"
4+
5+
using namespace std;
6+
7+
int main() {
8+
map<string, int> m;
9+
m["hello"] = 1;
10+
m["world"] = 2;
11+
cout << m << endl;
12+
return 0;
13+
}

16/02.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <iostream>
2+
#include <map>
3+
#include "printer.h"
4+
5+
using namespace std;
6+
7+
int main() {
8+
map<string, int> m;
9+
m.at("hello") = 1;
10+
m.at("world") = 2;
11+
cout << m << endl;
12+
return 0;
13+
}

16/printer.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#pragma once
2+
3+
#include <iostream>
4+
#include <utility>
5+
#include <type_traits>
6+
7+
namespace std {
8+
9+
template <class T, class = const char *>
10+
struct __printer_test_c_str {
11+
using type = void;
12+
};
13+
14+
template <class T>
15+
struct __printer_test_c_str<T, decltype(std::declval<T>().c_str())> {};
16+
17+
template <class T, int = 0, int = 0, int = 0,
18+
class = decltype(std::declval<std::ostream &>() << *++std::declval<T>().begin()),
19+
class = decltype(std::declval<T>().begin() != std::declval<T>().end()),
20+
class = typename __printer_test_c_str<T>::type>
21+
std::ostream &operator<<(std::ostream &os, T const &v) {
22+
os << '{';
23+
auto it = v.begin();
24+
if (it != v.end()) {
25+
os << *it;
26+
for (++it; it != v.end(); ++it)
27+
os << ',' << *it;
28+
}
29+
os << '}';
30+
return os;
31+
}
32+
33+
template <class T1, class T2>
34+
std::ostream &operator<<(std::ostream &os, std::pair<T1, T2> const &v) {
35+
os << '{' << v.first << ',' << v.second << '}';
36+
return os;
37+
}
38+
39+
}

16/slides.pptx

550 KB
Binary file not shown.

16/xmake.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
target("exec")
2+
add_files("01.cpp")

Presentation1.pptx

1.8 MB
Binary file not shown.

specifelse/.tasks

Whitespace-only changes.

specifelse/0.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include "ticktock.h"
2+
#include "randint.h"
3+
#include <vector>
4+
#include <algorithm>
5+
6+
#if 0
7+
__attribute__((noinline)) void uppercase(char *p, int n) {
8+
for (int i = 0; i < n; i++) {
9+
p[i] = ('a' <= p[i] && p[i] <= 'z') ? p[i] + 'A' - 'a' : p[i];
10+
}
11+
}
12+
#else
13+
__attribute__((noinline)) void uppercase(char *p, int n) {
14+
for (int i = 0; i < n; i++) {
15+
if ('a' <= p[i] && p[i] <= 'z')
16+
p[i] = p[i] + 'A' - 'a';
17+
}
18+
}
19+
#endif
20+
21+
int main() {
22+
int n = (int)1e7;
23+
std::vector<char> a(n);
24+
25+
for (int i = 0; i < n; i++) {
26+
a[i] = randint<char>(0, 127);
27+
}
28+
std::sort(a.begin(), a.end());
29+
30+
TICK(test);
31+
uppercase(a.data(), n);
32+
TOCK(test);
33+
34+
return 0;
35+
}

specifelse/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cmake_minimum_required(VERSION 3.18)
2+
3+
if (NOT CMAKE_BUILD_TYPE)
4+
set(CMAKE_BUILD_TYPE Release)
5+
endif()
6+
set(CMAKE_CXX_STANDARD 20)
7+
8+
project(main LANGUAGES CXX)
9+
10+
add_executable(main main.cpp)

specifelse/old/1.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include "ticktock.h"
2+
#include "randint.h"
3+
#include <vector>
4+
#include <algorithm>
5+
6+
__attribute__((noinline)) void uppercase(char *p, int n) {
7+
for (int i = 0; i < n; i++) {
8+
if ('a' <= p[i] && p[i] <= 'z')
9+
p[i] = p[i] + 'A' - 'a';
10+
}
11+
}
12+
13+
int main() {
14+
int n = (int)1e7;
15+
std::vector<char> a(n);
16+
17+
for (int i = 0; i < n; i++) {
18+
a[i] = randint<char>(0, 127);
19+
}
20+
21+
TICK(random);
22+
uppercase(a.data(), n);
23+
TOCK(random);
24+
25+
for (int i = 0; i < n; i++) {
26+
a[i] = randint<char>(0, 127);
27+
}
28+
std::sort(a.begin(), a.end());
29+
30+
TICK(sorted);
31+
uppercase(a.data(), n);
32+
TOCK(sorted);
33+
34+
return 0;
35+
}

specifelse/old/2.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "ticktock.h"
2+
#include "randint.h"
3+
#include <vector>
4+
#include <algorithm>
5+
6+
__attribute__((noinline)) void uppercase(char *p, int n) {
7+
for (int i = 0; i < n; i++) {
8+
p[i] = ('a' <= p[i] && p[i] <= 'z') ? (p[i] + 'A' - 'a') : p[i];
9+
}
10+
}
11+
12+
int main() {
13+
int n = (int)1e7;
14+
std::vector<char> a(n);
15+
16+
for (int i = 0; i < n; i++) {
17+
a[i] = randint<char>(0, 127);
18+
}
19+
20+
TICK(random);
21+
uppercase(a.data(), n);
22+
TOCK(random);
23+
24+
for (int i = 0; i < n; i++) {
25+
a[i] = randint<char>(0, 127);
26+
}
27+
std::sort(a.begin(), a.end());
28+
29+
TICK(sorted);
30+
uppercase(a.data(), n);
31+
TOCK(sorted);
32+
33+
return 0;
34+
}

specifelse/old/3.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "ticktock.h"
2+
#include "randint.h"
3+
#include <vector>
4+
#include <algorithm>
5+
6+
__attribute__((noinline)) void uppercase(char *p, int n) {
7+
for (int i = 0; i < n; i++) {
8+
p[i] = ('a' <= p[i] && p[i] <= 'z') ? (p[i] + 'A' - 'a') : p[i];
9+
}
10+
}
11+
12+
int main() {
13+
int n = (int)1e7;
14+
std::vector<char> a(n);
15+
16+
for (int i = 0; i < n; i++) {
17+
a[i] = randint<char>(0, 127);
18+
}
19+
20+
TICK(random);
21+
uppercase(a.data(), n);
22+
TOCK(random);
23+
24+
for (int i = 0; i < n; i++) {
25+
a[i] = randint<char>(0, 127);
26+
}
27+
std::sort(a.begin(), a.end());
28+
29+
TICK(sorted);
30+
uppercase(a.data(), n);
31+
TOCK(sorted);
32+
33+
return 0;
34+
}

specifelse/old/main.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include "ticktock.h"
2+
#include "randint.h"
3+
#include <vector>
4+
#include <algorithm>
5+
6+
__attribute__((noinline)) void uppercase_slow(char *p, int n) {
7+
for (int i = 0; i < n; i++) {
8+
if ('a' <= p[i] && p[i] <= 'z')
9+
p[i] = p[i] + 'A' - 'a';
10+
}
11+
//random: 0.020724s
12+
//sorted: 0.004538s
13+
}
14+
15+
__attribute__((noinline)) void uppercase_fast(char *p, int n) {
16+
for (int i = 0; i < n; i++) {
17+
p[i] = ('a' <= p[i] && p[i] <= 'z') ? (p[i] + 'A' - 'a') : p[i];
18+
}
19+
//random: 0.000735s (28x faster)
20+
//sorted: 0.000774s
21+
}
22+
23+
#define uppercase uppercase_fast
24+
25+
int main() {
26+
int n = (int)1e7;
27+
std::vector<char> a(n);
28+
29+
for (int i = 0; i < n; i++) {
30+
a[i] = randint<char>(0, 127);
31+
}
32+
33+
TICK(random);
34+
uppercase(a.data(), n);
35+
TOCK(random);
36+
37+
for (int i = 0; i < n; i++) {
38+
a[i] = randint<char>(0, 127);
39+
}
40+
std::sort(a.begin(), a.end());
41+
42+
TICK(sorted);
43+
uppercase(a.data(), n);
44+
TOCK(sorted);
45+
46+
return 0;
47+
}

specifelse/randint.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
#include <random>
4+
5+
template <class T>
6+
static T randint(T minVal, T maxVal) {
7+
static std::mt19937 gen(0);
8+
std::uniform_int_distribution<char> uni(minVal, maxVal);
9+
return uni(gen);
10+
}
11+

specifelse/ticktock.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
3+
#include <chrono>
4+
#include <cstdio>
5+
6+
#define TICK(x) auto bench_##x = std::chrono::steady_clock::now();
7+
#define TOCK(x) std::printf("%s: %lfs\n", #x, std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - bench_##x).count());

specmacro/xmake.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
target("a")
2+
add_files("*.cpp")

tools/qt-danmu.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ def __init__(self, parent=None):
5252
self.update()
5353

5454
def update(self):
55-
threading.Timer(1, self.update).start()
55+
threading.Timer(5, self.update).start()
5656
msgs = get_messages()
57-
print('update got:', msgs)
57+
# print('update got:', msgs)
5858
self.slm.setStringList(msgs)
5959

6060

0 commit comments

Comments
 (0)