GithubHelp home page GithubHelp logo

kernel's Introduction

Collection for GNU TeXmacs

Join the chat at https://gitter.im/texmacs/Lobby

Goals

Extract the Kernel of GNU TeXmacs with minimum modification. Git diffs on source code of this project should be easily backported to the SVN repo.

GSoC NOTICE

GSoC students all over the world are welcome to contribute on GNU TeXmacs starting from this project.

kernel's People

Contributors

da-liii avatar liuyuhui avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kernel's Issues

Google Test-Basic use of gtest

Recently I learned about memory and combined the article to analyze how TeXmacs memory pool works. Finally, I successfully compiled my first unit test module using gtest.

You can see this article(https://www.douban.com/group/topic/105715564/?dt_platform=com.douban.activity.qq_session&dt_dapp=1) to study how the memory pool in TeXmacs works. I mainly introduce the basic use of gtest.

Gtest is google's testing framework. It greatly saves the process of testing code. It is very simple to use. It uses macros to define test cases directly, and there are many rich macros to aid testing, such as assertions, predictive values, death tests, and so on. I use the TEST macro to test the program. It has two parameters. The first one is the name of the program to be tested without the extension, and the second is a supplement to the current TEST function.

Google wraps a series of macros of EXPECT_* and ASSERT_, and the difference between EXPECT series and ASSERT series is: when EXPECT_ fails, the case continues to execute; when ASSERT_* fails, it returns directly in the current function, the following statements will not be executed.

We mainly test the memory allocation rate. Considering that the return value of allocated memory function is unpredictable, I used the EXPECT_TRUE macro, which means that the input test case is correct.

By analyzing the source code, it can be seen that the function tm_new for allocating memory mainly includes two functions fast_new and new. This time, the test time of tm_new and fast_new is analyzed, and the rest is the time consumed by the function new .

The code is as follows.

/******************************************************************************
* MODULE     : fast_alloc_test.cpp
* DESCRIPTION: Test the time allocated for memory, the correctness 
*              of the returned result is not tested due to the type 
*			   of the return value.
* COPYRIGHT  : (C) 2019 Ze Wang
*******************************************************************************
* This software falls under the GNU general public license version 3 or later.
* It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
* in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
******************************************************************************/


#include "gtest/gtest.h"
#include "fast_alloc.hpp"
#include "tm_configure.hpp"

struct Complex { 
public: 
double re, im; 
Complex(double re_, double im_): re(re_), im(im_) {} 
~Complex() {} 
}; 

/******************************************************************************
* Tests on Common routines for memory. It mainly contains two functions 
* fast_new and new.
******************************************************************************/

TEST(fast_alloc,time_new=fast_new+new_){
	EXPECT_TRUE(tm_new<char>());
	EXPECT_TRUE(tm_new<char>('a'));
	EXPECT_TRUE(tm_new<Complex>(35.8, 26.2));
	EXPECT_TRUE(tm_new<int>(1));
	EXPECT_TRUE(tm_new<short int>(1));
	EXPECT_TRUE(tm_new<long int>(1));
}

/******************************************************************************
* Tests on Common routines for functions fast_new.
******************************************************************************/

TEST(fast_alloc,fast_new){
	EXPECT_TRUE(fast_new(sizeof(int)));
	EXPECT_TRUE(fast_new(sizeof(double)));
	EXPECT_TRUE(fast_new(sizeof(char)));
	EXPECT_TRUE(fast_new(sizeof(Complex)));
	EXPECT_TRUE(fast_new(sizeof(short int)));
	EXPECT_TRUE(fast_new(sizeof(long int)));
}

The results after running Linux are as follows.

1

We speculate that the new function in the tm_new function takes more time to execute.

References:

https://blog.csdn.net/zdy0_2004/article/details/56679754
http://www.cnblogs.com/coderzh/archive/2009/04/06/1426758.html
http://www.cnblogs.com/coderzh/archive/2009/04/08/1431297.html
http://www.cnblogs.com/coderzh/archive/2009/04/11/1433744.html
http://www.cnblogs.com/coderzh/archive/2009/04/12/1434155.html

The analysis of the benchmark folder

Benchmark is Google Benchmark, which is mainly used to test the benchmark function of functions in C++.
A great example is as follows.
demo.cpp:

#include <benchmark/benchmark.h>
#include <iostream>
#include <string>

using namespace std;

void demo()
{
string str = "hello world";
str.size();
}


static void BM_demo(benchmark::State& state) {
for (auto _ : state)
demo();
}
// Register the function as a benchmark
BENCHMARK(BM_demo); //register test function
BENCHMARK_MAIN(); //program entry

In the code above, demo() is the function to be tested. static void BM_demo(...) is a part of the benchmark framework, which is responsible for testing the performance of the function demo().
image
In the result above, the first column is the program name, the second column is the clock time that iterates once, the third column is the CPU time that iterates once, and the fourth column is the number of iterations of the loop.

In this project, a basic cpp file is list_bench.cpp. This is the code.

#include <benchmark/benchmark.h>
#include "list.hpp"


static list<long> gen(int64_t n) {
  auto normal = list<long>();
  for (long i=0; i<n; i++)
    normal << i;
  return normal;
}

static void N (benchmark::State& state) {
  auto list = gen(state.range(0));
  for (auto _ : state)
    N (list);
}
BENCHMARK (N)
  ->Arg(1)
  ->Arg(2)
  ->Arg(4)
  ->Arg(8)
  ->Arg(16)
  ->Arg(32)
  ->Arg(64)
  ->Arg(128)
  ->Arg(256)
  ->Arg(512)
  ->Arg(1024);

Gen(...) is used to generate a linked list, static void N(...) function is used to test the performance of the N(list) function.

Setting up a build environment in the Ubuntu14.04x64

According to the official GitHub installation instructions, we need to install Qt and guile1.8, then download the project code and build it with the command [cmake], Finally use the command [make] to install TeXmac. The difficult steps are [install Qt, install guile and install cmake], as explained below.

  1. Install Qt

    [Qt: Qt is a cross-platform C++ application development framework. It is widely used to develop GUI programs, which in this case is also called component toolbox. It can also be used to develop non-GUI programs such as console tools and servers.
    Qt Creator: Qt Creator is a cross-platform integrated development environment, especially for Qt developers, which is a part of the Qt SDK. It can be run on Windows, Linux/X11 and Mac OS X desktop operating systems, allowing developers to create applications for desktop environments and mobile device platforms. It includes a visual debugging tool and an integrated GUI layout and shape designer. ]
    The installation package used is qt-opensource-linux-x64-5.11.3.run
    Installation command:
    chmod +x qt.......
    ./qt......
    You can refer to this link [http://www.cnblogs.com/huicanlin/p/5279089.html] for configuration.

  2. Install guile

    [Scheme is a programming language, and Guile (Scheme interpreter and library) converts it into an embedded scripting language, which is a great way to introduce dynamics into static applications. It is powerful in building scalable applications.ใ€‘
    Three guile-related packages have been downloaded, namely guile-1.8_1.8.8+1-10_amd64.deb, guile-1.8-libs_1.8.8+1-10_amd64.deb, and guile-1.8-dev_1.8.8+1-10_amd64. Deb;
    The first two packages are currently installed and no error is reported.

  3. Install cmake

    [cmake: CMake is an open source cross-platform automation building system for managing software builds and is not dependent on a particular compiler. It can support multiple levels of directories, multiple applications, and multiple libraries. It uses configuration files to control the construction process in a similar way to Unix make, except that cmake's configuration file is named CMakeLists.txt. ใ€‘
    First, in ubuntu, enter the command [sudo apt-get install cmake], which will install a lower version of cmake, which generally needs to be upgraded by:
    sudo apt-get upgrade
    sudo apt-get install software-properties-common
    sudo add-apt-repository ppa:george-edison55/cmake-3.x
    sudo apt-get update

    [Intractable disease: apt-get install xx can not be successfully installed due to dependent package reasons]
    The solution:
    sudo apt-get -f autoremove

In the process of analyzing the code, I found that I need to master the cmake syntax, the relevant cmake learning links are as follows:
https://github.com/Akagi201/learning-cmake
Https://github.com/ttroy50/cmake-examples

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.