summaryrefslogtreecommitdiffstats
path: root/twin/tools/decobenchmark/main.cpp
blob: 59a6e676278f22974f30a6600e2bc75fff8f5d84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
 *
 * Copyright (c) 2005 Sandro Giessl <sandro@giessl.com>
 * Copyright (c) 2005 Luciano Montanaro <mikelima@cirulla.net>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include <tqtimer.h>

#include <kdebug.h>
#include <kconfig.h>
#include <kdecoration_plugins_p.h>
#include <kdecorationfactory.h>

#include <time.h>
#include <sys/timeb.h>
#include <iostream>


#include <kaboutdata.h>
#include <kapplication.h>
#include <kcmdlineargs.h>

#include "preview.h"
#include "main.h"

static KCmdLineOptions options[] =
{
	{ "+decoration", "Decoration library to use, such as twin3_plastik.", 0 },
	{ "+tests", "Which test should be executed ('all', 'tqrepaint', 'caption', 'resize', 'recreation')", 0 },
	{ "+repetitions", "Number of test repetitions.", 0 },
	{ 0, 0, 0 }
};

DecoBenchApplication::DecoBenchApplication(const TQString &library, Tests tests, int count) :
		m_tests(tests),
		m_count(count)
{
	KConfig twinConfig("twinrc");
	twinConfig.setGroup("Style");

	plugins = new KDecorationPreviewPlugins( &twinConfig );
	preview = new KDecorationPreview( plugins, 0 );

	if (plugins->loadPlugin(library) )
		kdDebug() << "Decoration library " << library << " loaded..." << endl;
	else
		kdError() << "Error loading decoration library " << library << "!" << endl;

	if (preview->recreateDecoration() )
		kdDebug() << "Decoration created..." << endl;
	else
		kdError() << "Error creating decoration!" << endl;

	preview->show();
}

DecoBenchApplication::~DecoBenchApplication()
{
	delete preview;
	delete plugins;
}

void DecoBenchApplication::executeTest()
{
	clock_t stime = clock();
	timeb astart, aend;
	ftime(&astart);

	if (m_tests == AllTests || m_tests == RepaintTest)
		preview->performRepaintTest(m_count);
	if (m_tests == AllTests || m_tests == CaptionTest)
		preview->performCaptionTest(m_count);
	if (m_tests == AllTests || m_tests == ResizeTest)
		preview->performResizeTest(m_count);
	if (m_tests == AllTests || m_tests == RecreationTest)
		preview->performRecreationTest(m_count);

	clock_t etime = clock();
	ftime(&aend);

	long long time_diff = (aend.time - astart.time)*1000+aend.millitm - astart.millitm;
	kdDebug() << "Total:" << (float(time_diff)/1000) << endl;
	quit();
}

int main(int argc, char** argv)
{
	TQString style = "keramik";
	// KApplication app(argc, argv);
	KAboutData about("decobenchmark", "DecoBenchmark", "0.1", "twin decoration performance tester...", KAboutData::License_LGPL, "(C) 2005 Sandro Giessl");
	KCmdLineArgs::init(argc, argv, &about);
	KCmdLineArgs::addCmdLineOptions( options );

	KCmdLineArgs *args = KCmdLineArgs::parsedArgs();

	if (args->count() != 3)
		KCmdLineArgs::usage("Wrong number of arguments!");

	TQString library = TQString(args->arg(0) );
	TQString t = TQString(args->arg(1) );
	int count = TQString(args->arg(2) ).toInt();

	Tests test;
	if (t == "all")
		test = AllTests;
	else if (t == "tqrepaint")
		test = RepaintTest;
	else if (t == "caption")
		test = CaptionTest;
	else if (t == "resize")
		test = ResizeTest;
	else if (t == "recreation")
		test = RecreationTest;
	else
		KCmdLineArgs::usage("Specify a valid test!");

	DecoBenchApplication app(library, test, count);

	TQTimer::singleShot(0, &app, TQT_SLOT(executeTest()));
	app.exec();
}
#include "main.moc"

// kate: space-indent off; tab-width 4;