mawinkle 6 年之前
父节点
当前提交
8d7029f5d2
共有 2 个文件被更改,包括 14 次插入3 次删除
  1. 2 0
      BigInt64.hpp
  2. 12 3
      test.cpp

+ 2 - 0
BigInt64.hpp

@@ -106,6 +106,7 @@ struct BigInt{
 	}
 	inline BigInt& chunkshiftLeft(int c){
 		if(c < 0)return chunkshiftRight(-c);
+		if(c >= size()){std::fill(begin(),end(),0);return *this;}
 		auto it1 = data.begin(); 
 		auto it2 = it1 + c;
 		while(it2 != data.end())*(it1++) = *(it2++);
@@ -114,6 +115,7 @@ struct BigInt{
 	}
 	inline BigInt& chunkshiftRight(int c){
 		if(c < 0)return chunkshiftLeft(-c);
+		if(c >= size()){std::fill(begin(),end(),0);return *this;}
 		auto it1 = data.rbegin(); 
 		auto it2 = it1 + c;
 		while(it2 != data.rend())*(it1++) = *(it2++);

+ 12 - 3
test.cpp

@@ -3,6 +3,11 @@
 
 #include <iostream>
 #include <chrono>
+unsigned long long nanoTime(){
+	using namespace std;
+	using namespace std::chrono;
+	return duration_cast<nanoseconds>(high_resolution_clock::now().time_since_epoch()).count();
+}
 template<typename T>
 std::ostream& operator<<(std::ostream& out, std::vector<T> o){
 	out << "[";
@@ -22,11 +27,15 @@ std::ostream& operator<< <char>(std::ostream& out, std::vector<char> o){
 	return out;
 }
 int main(){
-	BigInt a = {2};
-	for(int i = 0;i < 16;i++){
+	BigInt a = {1LL << 32};
+	for(int i = 0;i < 12;i++){
+		std::cout << a.toString().size() << " - stellig: " << std::flush;
+		auto t1 = nanoTime();
 		a = a.mult(a);
+		auto t2 = nanoTime();
+		std::cout << (t2 - t1) << " ns" << std::endl;
 	}
-	std::cout << a.toString() << "\n";
+	
 }
 int mian(){
 	cppsocket sock("192.168.178.79", 80);