気合入れて作ったvectorが本家より遅かった時の顔してる

アバター
MoNoQLoREATOR
記事: 284
登録日時: 14年前
住所: 東京

気合入れて作ったvectorが本家より遅かった時の顔してる

投稿記事 by MoNoQLoREATOR » 13年前

何故だ。何故なんだ…!
負けたorz

画像

検証用コード

CODE:

#define _CRT_SECURE_NO_DEPRECATE
#include "DxLib.h"
#include 
#include 
#include 
#define FW_WIN_MAIN_
#include "../fireworks/fireworks.h"

int main(){
	ChangeWindowMode(true);
	if(DxLib_Init() == -1) return(-1);

	typedef unsigned int uint;

	int beg, end;

	//本家(std::vector)の速度測定
	beg = GetNowCount();
	std::vector sv;
	for(uint i=0;i "  fv;
	for(uint i=0;i " 
class vector{
	X * content;
	uint Size;
	uint space;

	void ReSecure(uint size){
		X* another = static_cast(malloc(sizeof(X)*size) );
		fw::trade(content, another);
		uint oldsize = this->size();
		Size = 0;
		for(uint i=0;i& init(){
		zeroqure();
		return *this;
	}
	vector(){ Init(); }
	fw::vector& init(const fw::vector& req){
		zerosize();
		add(req);
		return *this;
	}
	vector(const fw::vector& req){
		Init();
		init(req);
	}
	fw::vector& operator= (const fw::vector& req){ return init(req); }
	fw::vector& init(const X& req){
		zerosize();
		add(req);
		return *this;
	}
	vector(const X& req){
		Init();
		init(req);
	}
	fw::vector& operator= (const X& req){ return init(req); }
	fw::vector& init(const X* arr, const uint size){
		zerosize();
		add(arr, size);
		return *this;
	}
	vector(const X* arr, const uint size){
		Init();
		init(arr, size);
	}

	fw::vector& secure(const uint size){
		if(size != space) ReSecure(size);
		return *this;
	}
	fw::vector& requre(const uint size){
		if(size > space) ReSecure(size);
		return *this;
	}
	fw::vector& addcure(const uint size){
		ReSecure(this->size()+size);
		return *this;
	}
	fw::vector& popcure(const uint size){
		uint popsize = this->size();
		if(size size() ) popsize = size;
		secure(popsize);
		return *this;
	}
	fw::vector& zerocure(){
		secure(0);
		return *this;
	}

	fw::vector& setsize(const uint size){
		int gap = this->size()-size;
		if(gap > 0) popsize(gap);
		if(gap & reqsize(const uint size){
		if(size > this->size() ) addsize(this->size()-size);
		return *this;
	}

	fw::vector& addsize(const uint size = 1){
		uint needsize = this->size()+size;
		if(needsize > space){
			if(needsize & addsize(const uint size, const X& req){
		uint needsize = this->size()+size;
		if(needsize > space){
			if(needsize & operator++ (){ return addsize(); }
	fw::vector operator++ (int){
		fw::vector old(*this);
		addsize();
		return old;
	}

	fw::vector& popsize(const uint size = 1){
		uint gap = this->size();
		if(size size()-size;
		for(uint i=0;isize()-1-i).~X();
		Size -= gap;
		return *this;
	}
	fw::vector& operator-- (){ return popsize(); }
	fw::vector operator-- (int){
		fw::vector old(*this);
		popsize();
		return old;
	}

	fw::vector& zerosize(){
		setsize(0);
		return *this;
	}

	fw::vector& add(){
		uint needsize = size()+1;
		if(needsize > space){
			if(needsize & add(const X& req){
		uint needsize = size()+1;
		if(needsize > space){
			if(needsize  & operator+= (const X& input){
		add(input);
		return *this;
	}
	fw::vector & operator& add(const X& req, const uint num){
		uint needsize = size()+num;
		if(needsize > space){
			if(needsize  & add(const fw::vector& input){
		requre(input.size() );
		for(uint i=0;i & operator+= (const fw::vector& input){
		add(input);
		return *this;
	}
	fw::vector & operator& input){
		add(input);
		return *this;
	}
	fw::vector& add(const X* arr, const uint size){
		requre(size);
		for(uint i=0;i& pop(const uint size = 1){ return popsize(size); }

	const X& access(const uint index) const {
		if(index >= size() ){
			#ifdef FW_VECTOR_POP_UP_
				MessageBox(NULL, "範囲外アクセスが発生しました", "エラー", MB_OK);
			#endif
			throw std::out_of_range("範囲外アクセスエラー");
		}
		return content[index];
	}
	const X& operator[] (const uint index) const { return access(index); }
	X& access(const uint index){
		const vector& ci = *this;
		return const_cast(ci.access(index) );
	}
	X& operator[] (const uint index){ return access(index); }
	X value(const uint index) const { return access(index); }

	const X* address(const uint index) const { return &access(index); }
	X* address(const uint index){ return &access(index); }
	const X* head() const { return address(0); }
	X* head(){ return address(0); }

	const X& last() const { return access(size()-1); }
	X& last(){ return access(size()-1); }
	X lastvalue() const { return last(); }

	X& next(){
		addsize();
		return last();
	}
	X nextvalue(){ return next(); }
	X& next(const X& req){
		add(req);
		return last();
	}
	X nextvalue(const X& req){ return next(req); }

	fw::vector member(const uint index, const uint size) const {
		fw::vector r(address(index), size);
		return r;
	}
	fw::vector member(const uint size) const {
		fw::vector r(address(0), size);
		return r;
	}

	fw::vector operator+ (const fw::vector& another) const {
		fw::vector r(*this);
		r += another;
		return r;
	}
	fw::vector operator+ (const X& another) const {
		fw::vector r(*this);
		r += another;
		return r;
	}

	uint size() const { return Size; }

	~vector(){
		for(uint i=0;i
#include 
#include 
#define FW_WIN_MAIN_
#include "../fireworks/fireworks.h"

int main(){
	ChangeWindowMode(true);
	if(DxLib_Init() == -1) return(-1);

	typedef unsigned int uint;

	int beg, end;

	//本家(std::vector)の速度測定
	beg = GetNowCount();
	std::vector sv;
	for(uint i=0;i "  fv;
	for(uint i=0;i " << (end-beg) << "ms" << std::endl;


	DxLib_End();
	return(0);
}

※全てデバッグコンパイルです

コメントはまだありません。